Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

monique champagne
monique champagne
761 Points

conditional challenge solution question

hey hi! ok so really trying this one and could use a little guidance! here is my code for this challenge and right off the bat im getting an error unexpected token on 17 '.' - which im guessing is the .toUpperCase method- but im not sure how else to write it! any advice? :) and thanks so much

//create a 5 question quiz. tally the answers. give a medal based upon how many right answers you get.

//set a var to 0 to start the tally
var correctAnswers = 0;

//write the questions out using a prompt
var questionOne = prompt('What is the coolest city in the US?');
var questionTwo = prompt('What is the best Nirvana Song');
var questionThree = prompt('What is the color of grass?');
var questionFour = prompt('Is coffee delicious?');
var questionFive = prompt('Is it going to get better?');
console.log(questionOne);

//create a variable to display a string in ranking
let rank = " ";

var answer1.toUpperCase() = 'New Orleans';
var answer2.toUpperCase() = 'Big Cheese';
var answer3.toUpperCase() = 'green';
var answer4.toUpperCase() = 'yes';
var answer5.toUpperCase() = 'yes';


//start the tally
if (questionOne === answer1) {
  correct += 1;
}
if (questionTwo === answer2) {
  correctAnswers += 1;
}

if (questionThree === answer3) {
  correctAnswers += 1;
}

if (questionFour === answer4) {
  correctAnswers += 1;
}

if (questionFive === answer5) {
  correctAnswers += 1;
}


//display the results

if (correctAnswers === 5) {
  document.querySelector('main').innerHTML = "Right on- you win a GOLD medal";
} else if (correctAnswers === 3 || correctAnswers === 4) {
  document.querySelector('main').innerHTML = "Good job- you got a SILVER medal";
} else if (correctAnswers === 2 || correctAnswers === 1) {
  document.querySelector('main').innerHTML = "Bronze is beautiful!!"
} else {
  document.querySelector('main').innerHTML = "It'll be better next time!"
}
Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,696 Points

Question updated with code formatting. Check out the Markdown Cheatsheet below the Add an Answer submission for syntax examples, or choose Edit Question from the three dots next to Add Comment to see how I improved the readability.

3 Answers

Steven Parker
Steven Parker
231,248 Points

You can't assign into a method, methods should be applied on the right side of the assignment:

var answer1.toUpperCase() = 'New Orleans';    // so instead of this...
var answer1 = 'New Orleans'.toUpperCase();    // do this
var answer1 = 'NEW ORLEANS';                  // or just this

Then, to be sure the answers match, don't forget to also modify the case of the responses:

if (questionOne === answer1) {                  // instead of this...
if (questionOne.toUpperCase() === answer1) {    // do this

And for future forum questions, take a look at these videos about using Markdown formatting to preserve the code's appearance (as I did here), and this one about sharing a snapshot of your workspace.

monique champagne
monique champagne
761 Points

thank you so much for the markdown formatting video!! i know i was missing something there :p and thanks also for the the method tip- ive reworked a lot of the code and once i get how to actually preserve the appearance- ill repost :) appreciate your help!

monique champagne
monique champagne
761 Points

im just testing what i learned from the video. ok so to start the formatting- i use backticks like this:

let firstName = "Monique";
let lastName = "Champagne";
let welcomeMessage = "Welcome to coding, " + firstName + " " + lastName + "!";
console.log(welcomeMessage);