I’m trying to write a code where if a randomly generated number matches one of the numbers in for loop it should output “True” if not then false.
let min = 20;let max = 50;
let a = (Math.floor(Math.random() * (max - min)) + min);
for (let i=0; i<30; i++){
if (i == a){
console.log("True");
break;
}
else{
console.log("False");
}
}
It ends up spamming false until the point it reaches the condition. Is there a way I can prevent this?
New contributor
Gogliko Sixarulidze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1