Guess the number game
by using math.floor and math.random
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<h1 id="h">Guess the Number from 1 to 10</h1>
<input id="num">
<button onclick="check()">Check</button>
<p id="result">You are Wrong/Right</p>
<p id="score">Score:10</p>
<script>
var num=document.getElementById("num");
var result=document.getElementById("result");
var score=document.getElementById("score");
var random=Math.floor(Math.random()*10)+1;
var totalscore=10;
function check(){
if(num.value==random){
result.innerText="You are right";
}
else{
totalscore=totalscore-1;
score.innerText="Score:"+totalscore;
result.innerText="You are wrong";
}
}
</script>
</body>
</html>
DOM CSS Style Manipulation
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
<style>
div{
background-color: red;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="box"></div>
<button onclick="change()">Change Color</button>
<script>
var box=document.getElementById("box");
console.log(box);
function change(){
box.style.backgroundColor="black";
}
</script>
</body>
</html>



Top comments (0)