when prompted i enter the number then it dont go thru the function it just makes current page = whatever i put when i get promted
INSTRUCTIONS : Create a while loop, while(currentPage !== null)
Inside of this loop, do the following:
- Detemine if the currentPage is an ending Create a function to do this! That will keep your code nice and clean.
Have a single parameter for your function, currentPage.
Use a loop to check if the current page matches any of the page numbers in endingPages
If you find the page within endingPages, return true. If you do not, return false.
Use this function in your while loop to determine if the current page is an ending.
- If the page is an ending, then print that page and exit the game Since your while loop ends if currentPage is null, assign null to the current page and then your loop will end on the next iteration.
Hint: It would probably look nice to print out something like "GAME OVER" or "The End" here... 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(i = 0 ; i <= endingPages.length ; i ++ ){
currentPage = endingPages[i]
if (endingPages[i] === pages.length){
return true
}else{
return false
}
}
}
}