Confirm

You have some programming skills. Time to make something you can show people! We're going to show you how to program a 'choose your own adventure' game. It'll have a basic story line, have the user make some choices, and have a happy ending. Then you can modify it as you wish and show off your creative talents!

One note before we begin. Each of the following exercises will ask you to add on to your previous code. Make sure not to delete or change anything that you did in a previous exercise. Good luck!

Instructions

  1. It's always polite to ask your user if they are ready to play.
  2. Using theconfirmcommand, make sure your user is ready to play. For example, I would use the sentence "I am ready to play!". Add whatever phrase you would like in the confirm.

Old enough to play?

This will involve two pieces of code:

1.First we will use prompt to ask a user for their age, like this:

2.var age = prompt("What's your age");

The variable age will hold the user's response.

  1. Then we will use anif/elsestatement based on the age of the user. Here's an outline of the code, similar to what we've seen before:

2.if(age is less than 13)
3.{
4. // do this code
5.}
6.else // "otherwise"
7.{
8. // do this code
9.}

Instructions

  1. Under the existing code, declare a variableage.
  2. Makeageequal toprompt("What's your age");. See the example above.
  3. Then write anif/elsestatement.Ifageis less than 13, usedocument.writeto tell the user that they're allowed to play but you take no responsibility.
  4. Else, usedocument.writeand give them an encouraging message to play on!

Adding some story

Let's set up the scene for your story. Under all your previous code, print out the following introduction, exactly as it is written.

"You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'"

Instructions

Print the introduction usingdocument.write. Remember that the introduction is astring, so make sure to keep it between quotes.

First move!

Next, your user is about to talk to Justin Bieber.

Instructions

  1. Under your existing code, print out the storyline:"Suddenly, Bieber stops and says, 'Who wants to race me?'"
  2. Then declare a variableuserAnswer. Make it equal apromptthat asks the user"Do you want to race Bieber on stage?". This will be the question that you ask your user.

The story heats up!

Now you have to create different scenarios. Good thing we know how to do that usingif/elsestatements.

IfuserAnsweris"yes", print out:"You and Bieber start racing. It's neck and neck! You win by a shoelace!"

Otherwise, print out:"Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'"

Remember:=is for assignment, and===is to check if things are equal!

Instructions

Use anif/elsestatement to write out the last part of this game!

Asking for feedback

It is worthwhile asking your user for feedback!

Instructions

  1. Create a variable calledfeedbackandpromptthe user to rate your game out of 10.
  2. Iffeedbackis greater than 8, print out:"Thank you! We should race at the next concert!"
  3. Otherwise, print out:
    "I'll keep practicing coding and racing."