html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- Created by Namit Jain -->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>My name is <span id="name"></span></p>
<h3 id="msg"></h3>
<form onsubmit = "func(event, person)">
<input type = "text" id = "colorguess">
</form>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
/* Created by Namit Jain */
body {
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Namit Jain
var person = {
name: "Namit Jain", age: 15, color: "blue", height: 180
};
function init() {
// document.write("My name is ", person.name, "<br>");
document.getElementById("name").innerText = person.name;
// document.write("<h3>You have to guess my favourite color</h3>")
document.getElementById("msg").innerText = "You have to guess my favourite color"
// person.name is better than person.color
}
function func(evt, person){
evt.preventDefault();
var mycolor = document.getElementById("colorguess").value;
if (mycolor.toLowerCase() != person.color){
document.getElementById("msg").innerText = "Wrongly guessed word: " + mycolor;
document.getElementById("colorguess").value = "";
}
else{
document.getElementById("msg").innerHTML = "<h1>You guessed it right!</h1>";
}
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run