Exercise 11 : Counting Drill Game (IMD)







 <!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<title> Counting Game 0v0 </title>

<style>

html {

font-family: Century Gothic;

margin-left: 20%;

background-color: #17b8d4;

    }

      

body {

max-width: 100px;

min-width: 480px;

    }

fieldset {

background-color:#ae94e0;

}

button {

background-color:#c9c012;

color: black;

border-radius: 30px;

width: 200px;

height: 60px;

}

</style>

</head>


<body>


<h1>Count Game!!!</h1>

<p> Let's count the shapes on the screen!!!</p>


<fieldset>

<canvas id="myCanvas" width="995" height="500" style="border:20px;">

</canvas>


<label> How many shapes do you see??? </label>

<input type="number" id="answer"> </input>

<!-- <button id="colors" onclick="colors()" > Colors </button> -->

<button id="eraser" onclick="eraser()" > Next </button>

<button id="compare" onclick="compare();eraser()" > Answer </button>


<p> <b> Score: </b> </p> <div id="myScore"> 0 </div>


<p id="demo"> </p>


</fieldset>


<script type = "text/javascript">

var score=0;

function colors()

{

var canvas = document.getElementById("myCanvas");

var ctx = canvas.getContext("2d");

x=Math.round(Math.random()*10+1);

for(f=1; f<=x;f++)

{

switch(f)

{

case 1: c="#3d42a1"; break

case 2: c="#3d42a1";break

case 3: c="#3d42a1"; break

case 4: c="#3d42a1";break

case 5: c="#3d42a1"; break

case 6: c="#3d42a1"; break

case 7: c="#3d42a1"; break

case 8: c="#3d42a1"; break

case 9: c="#3d42a1"; break

case 10: c="#3d42a1"; break

}

ctx.font = "30 px Century Gothic";

ctx.fillStyle=c;

ctx.fillRect(10+f*100,100, 50, 50);

}

}


function eraser()

{

var canvas = document.getElementById("myCanvas");

var ctx = canvas.getContext("2d");

ctx.clearRect(0,0,1200,300); 

colors();

}


colors()


function compare()

{

ans=document.getElementById("answer").value


if (ans==x) {

score += 1;

document.getElementById("myScore").innerHTML=score.toString()

document.getElementById("demo").innerHTML="nice one!! You are correct! 👍 "

}

else {

document.getElementById("demo").innerHTML="Sorry, you are wrong...😔 try again?"

}

}

</script>


</body>

</html>


Comments

Popular posts from this blog

Exercise 12 Responsive Web Page Design (WP)

Exercise 12 Chat box (IMD)