Open will1858 opened 5 years ago
Nice work on this project, @will1858! I really like how you can improve your odds by making certain choices and how you are using truthy conditions to simplify some of the game logic. 👍
Here are some ways I think your game can be improved. Can you try these out?
else if
after checking if a value is null
In the places where you call window.prompt
to collect a value, you are checking for null
before using the value, but if I click Cancel on a prompt, I will still see an error and your game stops running:
This happens because after you show the alert that I chose an invalid option, the code continues to run the next if
condition. For example:
if (codeword === null) {
window.alert('That is not an option')
}
if (codeword.toUpperCase().trim() === 'RUN') {
To avoid this, you can use an else if
instead of an if
for the second condition to ensure that it will only run when the value is not null
.
Do you mind updating the spots in your code where this is happening to use an else if
for the second condition so I'm unable to cause errors in your game?
At least one number value is collected and used in a comparison (don't forget to convert it into a number first)
I don't see a number being collected in your code. Do you mind introducing this into your story somehow?
After you’ve made your changes and pushed them to GitHub and your hosted site, give it a once-over to make sure it looks right, then comment back here and I’ll take another look.
Thanks! 🚀
completed
Your changes rock, @will1858! Good work! 🎉 :shipit:
Write a short choose-your-own adventure game in JavaScript
@egillespie Can you take a look at this? It's hosted here and meets the following criteria:
if
statementnull
/undefined
where appropriate&&
or||
) at least once, where it makes senseMath.random()
if
,else if
, andelse
to branch the story, based on user choicesprompt
andconfirm
functions (each at least once) to collect choices from the user (the entire story will take place in dialog boxes, so yourbody
element could actually be empty, apart from thescript
element to include your JavaScript)