following code is for above game Html javascript <H1 style="text-align: center; color:Blue">என் மனதில் இருக்கும் எண்ணை கண்டுபிடி?</H1> <h3 style="text-align: center; color:magenta" id="pscore">Score:0</h3> <h3 style="text-align: center; color:magenta" id="move">move:20</h3> <p style="text-align: center;">நான் 1-10க்குள் ஒரு எண்ணை நினைத்திருக்கிறேன். அதனை கனித்து கட்டத்திற்குள் எழுதுக</p> <center> <input id="guess" type="number" maxlength="2" style="border: solid;"> <button onclick="fcompar()">சரியா?</button> </center> <p id="info"></p> <p style="text-align: center;" id="ans"></p> <script lang="javascript"> var score=0; var heart = Math.floor(Math.random()*10)+1; console.log(heart); var move=20; var movebox= document.getElementById("move"); var guessbox =document.getElementById("guess"); var ans = document.getElementById("ans"); function fcompar() { let num = Number(guessbox.value); if(heart==num){ ans.textContent="Correct Answer. My Number: "+ heart; ans.style.color="green"; guessbox.style.borderColor="green"; document.getElementById("pscore").textContent="Score:"+ ++score; heart = Math.floor((Math.random()*10)+1); movebox.textContent="Move:"+ ++move; if(score==10) { document.write('<h1 style="text-align: center; color:green">You are winner</h1><br/> Score: 10') } return; } if(heart != num) { ans.textContent="Wrong Answer. "; if( heart > num ){ ans.textContent = ans.textContent+ " My number is greater than your number"; } if( heart < num ){ ans.textContent = ans.textContent+ " My number is less than your number"; } ans.style.color="red"; guessbox.style.borderColor="red"; movebox.textContent="Move:"+ --move; //console.log(heart,num); } if(num>10||num<1){ ans.textContent="Enter number between 1-10."; ans.style.color="black"; guessbox.style.borderColor="black"; //movebox.textContent="Move:"+ move; } if(move==0) { document.write('<h1 style="text-align: center; color:red">Game Over</h1><br/>'+"Score : "+ score) } } </script>இது பற்றிய கருத்தை commentல் சொல்லுங்கள்
Thursday, June 20, 2024
Guess the Number Javascript Game source code
Subscribe to:
Post Comments (Atom)
Change H1 text using buttons dynamically Javascript Sourcecode
Javascript Task How can i make it so that when a user clicks a button, the text from that button is shown...
No comments:
Post a Comment