answersLogoWhite

0


Best Answer

Note, I'm not testing this, but writing it on the fly. We'll see how it works :). Also, the formatting may be off.

while (true) {

var num = Math.round(Math.random() * 99) + 1;

if (numbers_found[num] === true) {

console.log(num, "was already found");

break;

}

numbers_found[num] = true;

console.log(num, 'added');

}

You can also change the 'console.log' to 'console.warn', 'console.error', or alert

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Note, i'm not testing this, but writing it on the fly. We'll see how it works :). Also, the formatting may be off.

var numbers_found = [];

while(true) {

var num = Math.round(Math.random() * 99) + 1;

if (numbers_found[num] === true) {

console.log(num, "was already found");

break;

}

numbers_found[num] = true;

console.log(num, 'added');

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in java script using while loop that generate random numbers between 1 to 100 and stop looping after it generate a same number twice?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Shell program to generate the prime numbers betwee 1 to 50?

2,3,5,7,9,11,13,17,19,23,29,31,37,39,41,43,47,49


Shell program to generate prime number between 1 and 50?

There are several shell programs available for download on the Internet that will generate prime numbers. The best way to find a prime number is through calculation, however.


Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values


C program to generate numbers from 1 to 100 divisible by 2?

(rand()&50+1)*2


What is the difference between Do While statements and Do For statements?

A "do while....." statement is a looping instruction to a program to repeat a stage in the program while some condition is true - e.g while a variable is negative, or, while one variable is less than another. A "do for ....." statement is a looping instruction to a program to repeat a stage in the program a set number of times - e.g for steps = 1 to 10, or, for steps = 1 to (some variable).


What is a C program to generate prime no?

not sure of the exact syntax but its quite hard to generate them, but you can go through a list of numbers, that could be 0-10000000 say, and check if it is prime by dividing it by all the numbers that are smaller than it


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


How do you generate palindrome number between the given range?

The generation of palindromic numbers within a given range is best done with a computer program. Space it limited so an example of program code cannot be shown here, but the Codecast website gives full guidance.


Q2 Write a program to print even numbers between 10 and 50?

You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.


What does it mean to generate random numbers in Java?

Generating random numbers in Java is somewhat of a misnomer because the numbers are actually semi-random.It means to use the program to obtain random integers to use in hypothetical situations such as statistics.


Does interpreter generate an object program from the source program?

No, that's what the compiler does.


Write a program of displaying numbers in shape of triangles by using looping?

#include <stdio.h> int main (void) { int i,j; for (i=1;i<5;i++) { for(j=1;j<=i;j++) printf("%d",j); printf("\n"); } return 0; }