educative.io

Educative

Breaking out of while loop even when input is greater than 50

Complete JavaScript Course: Build a Real World App from Scratch

var num = Number(prompt("Enter a number less than or equal to 50 "));

while(num > 50){
    console.log(`${num} > 50`)
    num = Number(prompt("Enter a number less than or equal to 50 "));
}

When I run this code, and during the prompt if I input a value greater than 50, the while loop runs only twice before breaking out. Not sure why this is the case


Course: Complete JavaScript Course: Build a Real World App from Scratch - Learn Interactively
Lesson: Coding Challenge: Input Validation - Complete JavaScript Course: Build a Real World App from Scratch


Course: Complete JavaScript Course: Build a Real World App from Scratch - Learn Interactively
Lesson: Coding Challenge: Input Validation - Complete JavaScript Course: Build a Real World App from Scratch


Course: Complete JavaScript Course: Build a Real World App from Scratch - Learn Interactively
Lesson: Coding Challenge: Input Validation - Complete JavaScript Course: Build a Real World App from Scratch

Hi @Meenu,
We have implemented a method concerned that users are not supposed to provide input via a prompt. We must use the Math.random() function to generate the input.
We hope Educative has inspired you to further your learning, and please drop us a note if you have any other questions or concerns. Thank you!