Sharp Tutorial
guess random number

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

Java Script

  • java script home
  • introduction
  • Variable Declare & Make Comment
  • operator
  • if else
  • loop
  • Array
  • Function
  • Java Script Objects
  • Java Script DOM

JS based examples

  • two number sum and diff programs
  • Pattern program in java script
  • zumble word quiz
  • Random number guess program
  • calculator in java script
  • digital clock in java script

HTML

  • HTML Home
  • Introduction
  • Commonly used tags
  • Formatting
  • Working with class
  • Apply Css
  • Layout
  • Link / Image
  • Html Forms
  • Html Tables
  • Responsive Design

CSS

CSS

  • Introduction
  • Types of Css
  • Background and Color
  • Css Formatting
  • Css Layout
  • Css Animation
  • Css Table
  • Css Effects
  • Css Pagination
  • Css Media Query

Java Script Number Guess Game

<html>
<body>

<form>
	<input type ="text" name="display" id="display"   disabled >
	<br>
	<input type="button" id = "start" value="start" onclick="s()" >
	<input type="button" id="ok" value="ok" onclick="o()" disabled="true">
</form>



</body>
</html>
<script type="text/javascript">
	var num;
	var attempt=1;
	var x = document.getElementById("display");
	x.disabled = false;
	function s()
	{
		console.log("inside s");
       num = Math.round(Math.random()* 100);
		var o = document.getElementById("ok");
		o.disabled = false;
      console.log(num);
      console.log(x.value);

	}
function o()
{
	var y = document.getElementById("display");
   if(y.value == num)
   {
   	  alert("sucess"+"    "+"attempts made are :" + attempt);
   	  console.log("sucess");
   	  y.disabled = true;
   	  y.value="";
   	  var o = document.getElementById("ok");
		o.disabled = true;
   }  
   else
   {
   	if(y.value == " ")
   	{
      alert("enter a number");
      attempt++;
   	}
   	else
   	{
   	if(y.value > num)
   	{
   	alert("number is smaller then "+y.value);
   	attempt++;
   	y.value="";
   }
   else
   {
   	alert("number is greater then "+y.value);
   	attempt++;
   	y.value = " ";
   }}
   }
   
}

</script>
 
[codepen_embed height="265" theme_id="default" slug_hash="povEOoV" default_tab="js,result" user="rajputadesh"]See the Pen povEOoV by rajput adesh (@rajputadesh) on CodePen.[/codepen_embed]

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial