Javascript loops

Ads

 
 

Share on Google+Share on Google+

Jeevan kumar
Javascript loops
1 Answer(s)      7 years ago
Posted in : Development process

Write a JavaScript code, - for guessing any number between 1 to 20. run the loop till you not get

correct number. Use prompt() box to input number from user.

Ads
View Answers

October 20, 2010 at 3:02 PM


Hi Friend,

Try the following code:

<SCRIPT LANGUAGE="JavaScript">
var guess;
var rno=Math.round(Math.random()*(19)+1);
while(guess!=rno){
guess=window.prompt("Guess Number from 1 to 20");
if (guess==rno){
alert('Congratulations! You have guess the number!');
}
if (rno<guess){
alert('Number is less than '+ guess);
}
if (rno>guess){
alert('Number is greater than '+ guess);
}
if (guess==''){
alert('Guess a number!');
}
}
</SCRIPT>

Thanks


Ads









Related Tutorials/Questions & Answers:
Javascript loops
Javascript loops  Write a JavaScript code, - for guessing any number between 1 to 20. run the loop till you not get correct number. Use prompt...: <SCRIPT LANGUAGE="JavaScript"> var guess; var rno=Math.round(Math.random
Use javascript loops..
Use javascript loops..  Write a Javascript code to create a redirection script based on day of the week
Advertisements
Use javascript loops..
Use javascript loops..  Write a JavaScript code to find a number of unique letters in string. (Eg. if keyword is Tajmahal, Tajmahal count will be '5' , it only takes these letters T,j,m,h,l , not taken the letter a because
Use javascript loops..
Use javascript loops..  Write a Javascript code, so that numbers...(" "); for(var k=q; k>=1;k--){ document.write(" "); } for(var j=1;j<=i;j++){ document.write(" "); document.write(j); } document.write("<br>"); q
Solve using only Javascript loops...
Solve using only Javascript loops...  Write a JavaScript code, 1) to find a number of unique letters in string. (Eg. if keyword is unique, Unique count will be '4') 2) so that numbers appear in following format, 1 1 2
JavaScript Loops Function
JavaScript Loops Types: In Java programming language a loop is a language... a function or method calls itself). JavaScript provides for, while, do-while, and foreach loop. Following examples will help you to learn loops: JavaScript Loop
Loops
Loops  ??Using for loops, Write a program to simulate a clock countdown. The program prompts the user to enter the number of seconds, displays a message at every second, and terminates when the time expires. Use method
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Loops
Loops  Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Loops
Loops  by using drjava q1.Write code that uses nested loops to print the following patterns: Pattern1: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 Pattern 2: 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 q2.Write code
Loops
3.10. Loops Loops are the essential part of the program that have.... More than one loops can be used several times in a script. Loops makes easy... instructed for repetition of the code. PHP Loops In PHP, like other programming
nested for loops
"); } } } }   Close your loops before going
use of loops and screenshots
use of loops and screenshots  1.how to use loops in netbeans? 2.how to draw a correct screenshot
Java - Declaring variables in for loops
Java - Declaring variables in for loops  Java - Declaring variables in for loops
How to read loops in Java
How to read loops in Java  Example that explains how to read loop in Java
JavaScript
JavaScript  clone JavaScript
LOOPS - Java Interview Questions
LOOPS   how to find out unique number of elements in given array?{1,2,5,3,2,1,1,7,2,3,0,1,5} output is: 1-4 2-3 3-2 5-2 0-1 7-1 i want source code plz help me
loops , control structures
loops , control structures  a simple java program to print 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
javascript
javascript  Hi deepak, how to write form validation on javascript
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  write a program to display implement about browsers using javascript
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript

Ads

 
Advertisement null

Ads