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 JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

santos mena
santos mena
868 Points

2 right answers of 5 ... No matter if I answer all 5 correct!

Hello everybody, hope somebody can spot the issue... No matter if I answer the all 5 questions correct, I got a "bronze medal" because I answered 2 of 5 questions correct ...

Answers are as follows:

  1. Merida
  2. Aries
  3. Sebastian
  4. Cancun
  5. Javascript

Thanks in advance!!

// inicia el cuestionario, no hay respuestas correctas - dejamos el marcador en cero
var marcador = 0;

// hacemos las preguntas
var pregunta1 = prompt("En que estado esta Merida?");
if (pregunta1.toUpperCase() === 'MERIDA') {
marcador += 1;
}

var pregunta2 = prompt("Cual es el nombre de tu mascota?");
if (pregunta2.toUpperCase() === 'ARIES') {
marcador += 1;
}

var pregunta3 = prompt("Como se llama tu hijo?");
if (pregunta3.toUpperCase === 'SEBASTIAN') {
marcador += 1;
}

var pregunta4 = prompt("En que ciudad vives?");
if (pregunta4.toUpperCase === 'CANCUN') {
marcador += 1;
}

var pregunta5 = prompt("Con que programa hiciste esto?");
if (pregunta5.toUpperCase() === 'JAVASCRIPT') {
marcador += 1;
}

// damos resultados 

document.write("<p>Tienes " + marcador + " de 5 respuestas correctas!</p>");


// mostramos recompensa

if (marcador === 5) {
document.write("<p><strong>Ganaste medalla de oro!</strong></p>");
} else if (marcador >= 3) {
document.write("<p><strong>Ganaste medalla de plata!</strong></p>");
} else if (marcador >= 1) {
document.write("<p><strong>Ganaste medalla de bronce!</strong></p>");
} else {
document.write("<p><strong>No hay medalla para ti. Necesitas estudiar mas!</strong></p>");
}

4 Answers

Hi Santos,

Looks like you have two function calls of .toUpperCase() that are missing parentheses.

// pregunta3.toUpperCase
// pregunta4.toUpperCase

Hope this helps,

Cheers

santos mena
santos mena
868 Points

Thanks a lot Robert! I appreciate your help, I'm getting closer this time got a silver medal =) will keep pushing for the gold! Even though I tried to find "errors" in js console but it didn't throw me what you saw ... Felt a bit dissapointed thought JS Console was helpful with this type of "newbie" errors. Anyway thank you!!

Interesting. I'm getting

Tienes 5 de 5 respuestas correctas!

Ganaste medalla de oro!

The console will let you know when there's a syntax error, but leaving off the parens in this case is not a syntax error. It returns the function definition of toUpperCase instead of the upper case value of marcador.

Here is the fixed code, you should be able to copy / paste it into the developer console to run it and verify the fix.

// inicia el cuestionario, no hay respuestas correctas - dejamos el marcador en cero
var marcador = 0;

// hacemos las preguntas
var pregunta1 = prompt("En que estado esta Merida?");
if (pregunta1.toUpperCase() === 'MERIDA') {
marcador += 1;
}

var pregunta2 = prompt("Cual es el nombre de tu mascota?");
if (pregunta2.toUpperCase() === 'ARIES') {
marcador += 1;
}

var pregunta3 = prompt("Como se llama tu hijo?");
if (pregunta3.toUpperCase() === 'SEBASTIAN') {
marcador += 1;
}

var pregunta4 = prompt("En que ciudad vives?");
if (pregunta4.toUpperCase() === 'CANCUN') {
marcador += 1;
}

var pregunta5 = prompt("Con que programa hiciste esto?");
if (pregunta5.toUpperCase() === 'JAVASCRIPT') {
marcador += 1;
}

// damos resultados 

document.write("<p>Tienes " + marcador + " de 5 respuestas correctas!</p>");


// mostramos recompensa

if (marcador === 5) {
document.write("<p><strong>Ganaste medalla de oro!</strong></p>");
} else if (marcador >= 3) {
document.write("<p><strong>Ganaste medalla de plata!</strong></p>");
} else if (marcador >= 1) {
document.write("<p><strong>Ganaste medalla de bronce!</strong></p>");
} else {
document.write("<p><strong>No hay medalla para ti. Necesitas estudiar mas!</strong></p>");
}
santos mena
santos mena
868 Points

I know, I just realized answer for question one was "wrong" in my code, so instead of Merida was typing "Yucatan" whis is ACTUALLY the right answer! =( I guess is time for a coffee to wake up!! Thank you very much Robert for taking the time to test it on your side!

Steven Velazquez
Steven Velazquez
7,278 Points

I just realized that in the video solution, the instructor makes the same common mistake. Maybe it should be corrected. :)))