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

Tyler Lundgren
Tyler Lundgren
6,826 Points

missing a ) on line three and i cant find where, please help!!!

var guess = 0; function randomNum( lower, upper ) { var guess1 = prompt ("I am thinking of a number between" lower " & " upper " what is it?"); var random = math.floor(math.random() * (upper - lower+ 1)) + lower; return random; guess += 1; if parseInt(guess1) === parseInt(randomNum) { document.write('<p> You guessed it! <p>'); alert("Ok lets do it one more time!"); } else { alert("Try again!"); } }; randomNum( 10, 20 );

Tyler Lundgren
Tyler Lundgren
6,826 Points

not line three, but in the prompt to user... var guess1 = prompt ("i am thinking of a number between" lower "&" upper "what is it?");

1 Answer

Hey Tyler,

It looks like the error you're you're getting has to do with the string passed into prompt the function. To combine strings with variables, you'll want to use the + operator.

Here's an example:

var guess1 = prompt ("I am thinking of a number between " + lower + " & " + upper + " what is it?"); 

Another way you could create the string is by using something called template literals. This is what your same code would look like using template literals:

var guess1 = prompt (`I am thinking of a number between ${lower} & ${upper} what is it?`); 

One other thing I noticed when testing your code is that you'll want to add an opening and closing brace around your if statement, like this:

if (parseInt(guess1) === parseInt(randomNum))

Hope that helps!

-Brandon