Code-Along: Quiz About Me
In this activity, start building a quiz about yourself! Other people will be able to go to your website, and test their knowledge of YOU!
Getting Started
You can start by forking this template to jump right into the activity.

Updating HTML
The starter project has some information on it... but it might not be accurate to you!
- Open the index.html file by clicking it on the left
- Find the
<h1>part in the code - Change the name "Joseph" to your name (unless your name is Joseph!)
- Find the
<p>part under that - Change the blurb to be a unique fun fact about you
Make sure to save the project to see the changes update!

Updating CSS
The starter project has some stylistic choices that are good, but you can make them your own!
- Open the style.css file by clicking it on the left
- Find the
background:part in the code - Change the color to update your site's background!
- Similarly, change the text color right under that with the
color:part - Feel free to change the font as well
- NOTE: There is a list of built-in fonts if you scroll down in the style.css file :)
Updating JS
The starter project has a picture for the favorite animal, but you can change it!
- Open the script.js file by clicking it on the left
- Find the line that has a URL (starting with
https://) - Open a new tab and find a new image
- Right click the image and select the "Copy image link" option
- Remove the old URL, and replace it by pasting your new URL with
Ctrl+V
Now, the page should really be yours! It's time to start making the quiz.
Displaying a Message
The first thing to do is make the startQuiz function display a message! Under the function startQuiz() { line, above the }, add a new alert statement:
alertkeyword- Parentheses
() - Quotation Marks
""within the() - A message within the
"" - A semi-colon
;
The code in the script.js file should look something like this!
function startQuiz() {
alert("Welcome to my quiz!");
}
Commanding the Function: Already Done!
Code like this should already be within the index.html file:
<button onclick="startQuiz()">Take a quiz about me!</button>
This connects the startQuiz function definition in the script.js file to the button on the page. Click the button to see it working!
NOTE: From here on out, every change will be in the script.js file!
Adding a Greeting
When welcoming someone to our quiz, we should ask for their name and then greet them. We can ask for their name using prompt, store their answer in a variable, and reply.
- Under the
alert(still above}), make a new line - Use a
promptto ask the user for their namepromptkeyword- Parentheses
() - Quotation Marks
""in the() - A question in the
""
Save the project and click the button to see the prompt appear! Now we just have to save the answer.
- Put your cursor to the left of the
promptline - There, create a new variable named
nameletname=
- Set the
namevariable to equal to theprompt
Now the user's name is stored in the name variable. We can use it to say hi!
- Make a new line under the
prompt(still above}) - Add an
alertthat says"Hi, " - Between the
(and), add+ nameto add thenamevariable value to the end of the message
Save, click, and see what happens! It should respond based on the user input, saying "Hi, Person" for Person.
The added code should look something like this:
let name = prompt("What is your name?");
alert("Hi, " + name);
Asking a Quiz Question
Okay okay okay. We have added a lot of stuff, but what does any of this have to do with a quiz about me? NOTHING!
Well, it's time to change that! Let's ask our first quiz question :)
We can use prompt to ask the question, and create a new variable named answer1 to store the user's answer.
letkeyword- Variable name (
answer1) =Equals signpromptkeyword()Parentheses""Quotation Marks within the()- Message within the
"" ;Semi-colon at the end
The added code should look something like this:
let answer1 = prompt("What is my name?");
Click the button and see what happens - it asks the question, but doesn't do anything!
Checking the Answer
Now that we have their answer, we should check to see if it's correct. If it is, they can increase their points by 1.
We can do this with an if statement!
ifkeyword()Parentheses- Condition inside of the
(and)- Left value
answer1 ==Double equals- Right value
"Joseph"(unless your name is NOT Joseph)
- Left value
{}Curly brackets- Body between
{and}- display a messagealert, parentheses, quotes,"CORRECT"message!
The added code should look something like this:
if (answer1 == "Joseph") {
alert("CORRECT");
}
Now the quiz taker can start seeing how well they know you!
Asking Another Question
Now, a quiz with one question isn't very interesting. Luckily, we can do basically the exact same thing we just did to add one more question!
- Create a
promptasking the question - Store the users answer in a new variable
- Use an
ifstatement to check if their answer==the correct one - If it's correct, say so!
The added question might look something like this:
let answer2 = prompt("Where was I born?");
if (answer2 == "Cleveland") {
alert("CORRECT")
}
Code
By the end of the activity, your code in the script.js file should look something like this:
function startQuiz() {
alert("Welcome!");
let name = prompt("What is your name?");
alert("Hi, " + name);
let answer1 = prompt("What is my name?");
if (answer1 == "Joseph") {
alert("CORRECT")
}
let answer2 = prompt("Where was I born?");
if (answer2 == "Cleveland") {
alert("CORRECT")
}
}
Next Steps
Try adding more questions in the same way! You can also use an else to display an "INCORRECT" message if the quiz taker gets a question wrong :)