After entering a number when prompted, the current page does not go through the function as expected. Instead, it simply changes to whatever number I input when prompted.
INSTRUCTIONS : Create a while loop with the condition while(currentPage !== null)
Within this loop, follow these steps:
- Determine if the currentPage is an ending. To ensure clean code, create a function for this task.
Your function should have a single parameter, currentPage.
Use a loop to compare the current page with the numbers in endingPages.
If the matching page is found within endingPages, return true; otherwise, return false.
Utilize this function in the while loop to confirm if the current page marks an ending.
- If the page is indeed an ending, display that page and exit the game. Since the while loop stops when currentPage is null, set the current page to null for the loop to end in the next iteration.
Hint: It would be visually appealing to print something like "GAME OVER" or "The End" at this point... CODE
console.log(pages[0]);
let endingPages = [4, 9, 13, 17, 19, 20];
let currentPage = 0;
let pages = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
// Your Code Here.
currentPage = prompt("Enter page:")
ending(currentPage);
function ending (currentPage){
while(currentPage !== null) {
for(let i = 0; i <= endingPages.length ; i++ ){
currentPage = endingPages[i]
if (endingPages[i] === pages.length){
return true
}else{
return false
}
}
}
}