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:
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.
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
}
}
}
}
I think there is a lot of misinterpretation here. Ultimately currentPage never changes because function parameters in Javasript are pass-by-value
Either way in your code I do not see an attempt to print out currentPage after the user has been prompted and the function called
Ultimately your function should still return what you want, and you only need to test whether it returns true or false, by if (ending(currentPage)) { console.log("Game Over;"); }
if (ending(currentPage)) { console.log("Game Over;"); }
2 additional obvious flaws in the provided code:
while
loop inside the function is redundant, currentPage should never be null
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.