CODING:
<!DOCTYPE html>
<html>
<body>
<p>Creating and using an object method.</p>
<p>An object method is a function definition, stored as a property value.</p>
<button onclick="set()">Click ME!</button>
<p id="demo"></p>
<script>
var person = {
firstName: null,
lastName : null,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
function set(){
var f=prompt("Enter Your First Name...");
var l=prompt("Enter Your Last Name...");
person.firstName=f;person.lastName=l;
document.getElementById("demo").innerHTML = person.fullName();
}
</script>
</body>
</html>
<html>
<body>
<p>Creating and using an object method.</p>
<p>An object method is a function definition, stored as a property value.</p>
<button onclick="set()">Click ME!</button>
<p id="demo"></p>
<script>
var person = {
firstName: null,
lastName : null,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
function set(){
var f=prompt("Enter Your First Name...");
var l=prompt("Enter Your Last Name...");
person.firstName=f;person.lastName=l;
document.getElementById("demo").innerHTML = person.fullName();
}
</script>
</body>
</html>
Comments
Post a Comment