Skip to content

Instantly share code, notes, and snippets.

@kshitij-srv
Created December 20, 2018 21:37
Show Gist options
  • Save kshitij-srv/e2a0d7b130658cb9c67ebf4cfd1dca86 to your computer and use it in GitHub Desktop.
Save kshitij-srv/e2a0d7b130658cb9c67ebf4cfd1dca86 to your computer and use it in GitHub Desktop.
<p>Animal's name: <input type="text" id="f" size="10"></p>
<p>Animals sound: <input type="text" id="s" size="10"></p>
<button id="b" class="myButton">Introduce Animal</button>
<span id="write"></span>
<script id="jsbin-javascript">
var theButton = document.getElementById("b");
theButton.onclick = onButtonClick;
function Animal(name, sound) {
this.name = name ? name : this.name;
this.sound = sound ? sound : this.sound;
}
Animal.prototype.introduce = function() {
return this.sound + "! I am a " + this.name;
}
Animal.prototype.name = "Pikachu";
Animal.prototype.sound = "Pika-pika";
function introduceAnimal( first, second ) {
var animal = new Animal(first, second);
return animal.introduce();
}
function onButtonClick() {
var box1 = document.getElementById("f").value;
var box2 = document.getElementById("s").value;
var result = introduceAnimal( box1, box2 );
var place = document.getElementById("write");
place.innerHTML = result;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var theButton = document.getElementById("b");
theButton.onclick = onButtonClick;
function Animal(name, sound) {
this.name = name ? name : this.name;
this.sound = sound ? sound : this.sound;
}
Animal.prototype.introduce = function() {
return this.sound + "! I am a " + this.name;
}
Animal.prototype.name = "Pikachu";
Animal.prototype.sound = "Pika-pika";
function introduceAnimal( first, second ) {
var animal = new Animal(first, second);
return animal.introduce();
}
function onButtonClick() {
var box1 = document.getElementById("f").value;
var box2 = document.getElementById("s").value;
var result = introduceAnimal( box1, box2 );
var place = document.getElementById("write");
place.innerHTML = result;
}
</script>
var theButton = document.getElementById("b");
theButton.onclick = onButtonClick;
function Animal(name, sound) {
this.name = name ? name : this.name;
this.sound = sound ? sound : this.sound;
}
Animal.prototype.introduce = function() {
return this.sound + "! I am a " + this.name;
}
Animal.prototype.name = "Pikachu";
Animal.prototype.sound = "Pika-pika";
function introduceAnimal( first, second ) {
var animal = new Animal(first, second);
return animal.introduce();
}
function onButtonClick() {
var box1 = document.getElementById("f").value;
var box2 = document.getElementById("s").value;
var result = introduceAnimal( box1, box2 );
var place = document.getElementById("write");
place.innerHTML = result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment