The correct answer is:
Change the true in line 4 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely
The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.
1 var SECRET_PASSWORD = "karel";
2
3 function start(){
4 while(true){
5 var password = readLine("Enter your password: ");
6 if(password == SECRET_PASSWORD){
7 println("You got it!");
8 }
9 println("Incorrect password, please try again.");
10 }
11 }
JavaScript
Which of the following will fix this program?
Change the true in line 4 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely
Change the true in line 4 to be password == SECRET_PASSWORD so that the program doesn’t loop infinitely
Add a break; statement after line 7 so that the program doesn’t loop infinitely
Put line 9 inside of an else statement
1 answer