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 trialKathleen OKeife
1,960 PointsI don't understand why this fails on correctGuess.
/*
- Store correct answers
- When quiz begins, no answers are correct */
let correctGuess = 0
// 2. Store the rank of a player let playerRank = ("No crown");
// 3. Select the <main> HTML element document.querySelector = "main";
/*
- Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers
*/
const qOne = prompt("Largest city in FL"); if (qOne.toUppercase() === "MIAMI"){ correctGuess += 1; }
const qTwo = prompt("Place where Disneyworld is"); if (qTwo.toUppercase() === "ORLANDO"){ correctGuess += 1; }
const qThree = prompt("Place where Busch Gardens is"); if (qThree.toUppercase() === "TAMPA"){ correctGuess += 1; }
const qFour = prompt("County with Manatee River"); if (qFour.toUppercase() === "MANATEE"){ correctGuess += 1; }
const qFive = prompt("Place where Univ of FL is"); if (qFive.toUppercase() === "GAINESVILLE"){ correctGuess += 1; }
/*
- Rank player based on number of correct answers
- 5 correct = Gold
- 3-4 correct = Silver
- 1-2 correct = Bronze
- 0 correct = No crown */
if (correctGuess === 5){
playerRank = "Gold"
} else if (correctGuess >=3){
playerRank = "Silver";
} else if (correctGuess <=2){
playerRank= "Bronze";
} else {
playerRank = "No Crown";
}
// 6. Output results to the <main> element
main.innerHTML =
<h2> You got {correctGuess} right.
Your rank is {playerRank}</h2>
9 Answers
Steven Parker
231,275 PointsCan you give us a fresh snapshot? Also, exactly what steps do you use to "run the code"?
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 Points// .toUppercase(), the c in case is not capitalized, it should be like this for all if statements above:
.toUpperCase()
// main.innerHTML = <h2> You got {correctGuess} right. Your rank is {playerRank}</h2>, should be like this:
main.innerHTML = `<h2> You got ${correctGuess} right. Your rank is ${playerRank}</h2>`;
// I did not see what the main was referenced to but if you fix the above issues, your code should run fine.
// when I was testing it I had to console.log the correctGuess and playerRank and they were working perfectly fine
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 PointsJust spotted a flaw in your code:
// it's here > else if (correctGuess <=2 ...
// if you have 0 correctGuesses it will still return the outcome for this statement, in this case, playerRank= "Bronze";
// it will never be able to get to
else {
playerRank = "No Crown";
}
// I will write it like this, so that if the correctGuess is 0 the playerRank would equal to "No Crown":
else if (correctGuess <=2 && correctGuess > 0) {
playerRank= "Bronze";
}
Kathleen OKeife
1,960 PointsI made your suggested changes. TY. I posted the code because it still fails on correctGuess.
Kathleen OKeife
1,960 PointsI get an error that correctGuess is already declared and it fails when I run it.
Steven Parker
231,275 PointsI didn't see that issue in the snapshot, but I did spot several spellings of "toUpperCasease" instead of "toUpperCase".
Also "main" still needs to be defined.
Kathleen OKeife
1,960 PointsI fixed all of that. Here is the link to the snapshot. Same error. correctGuess already declared. Hope you can figure this out. I'm stumped. Thanks for helping.
Steven Parker
231,275 PointsYou have "toUppercase" (with lower-case "c") instead of "toUpperCase" (with capital "C") in several places.
Also, it looks like "main" has not been defined, and your template literal tokens are missing the "$" symbol.
And when posting code to the forum, use Markdown formatting to preserve the appearance, or share the entire workspace by making a snapshot and posting the link to it.
Steven Parker
231,275 PointsUPDATE: There's an issue with the method calling sequence on line 13:
const main = document.querySelector = "main"; // original
const main = document.querySelector("main"); // corrected
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 Points// .toUpperCasease(), 4 of your if statements have this when it should be
.toUpperCase()
// your main is not defined, so replace document.querySelector = 'main', with this:
const main = document.querySelector('main');
// this should work now
Kathleen OKeife
1,960 PointsI fixed all of that. Here is the link to the snapshot. Same error. correctGuess already declared. Hope y can figure this out. I'm stumped. Thanks for helping.
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 Points// const main = document.querySelector = "main"; this is wrong, should be
const main = document.querySelector("main");
Kathleen OKeife
1,960 PointsTY, Stivan. I corrected that but the same error on correctGuess. Here is the corrected code.
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 Points// I'm still seeing the
const main = document.querySelector = ("main");
// did you link the up-to-date code?
// also where are you getting the error from? in the console.log?
Kathleen OKeife
1,960 PointsI see. The double =. I fixed that but when I run to code in the console, I get this:
VM40:1 Uncaught SyntaxError: Identifier 'correctGuess' has already been declared
ygh5254e69hy5h545uj56592yh5j94595682hy95
7,934 PointsJust tested the fresh snapshot and there is nothing wrong with your code. It works perfectly fine.
Kathleen OKeife
1,960 PointsThank you so much Steven and Stivan. I had no idea should not cut and paste in the console. The instructor showed us to do that in "Developer Tools".
I did appreciate the guidance on the poorly written code. ;-)
Kathleen OKeife
1,960 PointsKathleen OKeife
1,960 PointsI cut and paste the code from the Treehouse Workspace to the console and run it there. Here is a new snapshot.
https://w.trhou.se/30m5a2p7xs
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIt looks like the final issue is how you run the project. To start a workspace, click the preview button, it's the little icon that looks like an eye in the upper right. This will cause a new page to open in your browser showing the output from your project.
You won't need to "cut and paste" any code, and that should eliminate the error.