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 trialmark-anthony Richinsin
1,158 PointsGetting unexpected syntax error at my last line.
Does anyone know why my code does not run?
// Collect input from a user
let high = prompt(enter a high number
);
let low = prompt(enter a lower number
);
// Convert the input to a number
high = parseInt(high);
low = parseInt(low);
if (low && high{
// Use Math.random() and the user's number to generate a random number
const randomNumber= Math.floor(Math.random() * (high - low + 1)) + low;
// Create a message displaying the random number
console.log(An random number between ${high} and ${low} is ${randomNumber}
);
}else {
console.log(`Your input is not a number.Try again.);
}
1 Answer
Blake Larson
13,014 Pointslet high = prompt("enter a high number"); //<-- quotes
let low = prompt("enter a lower number"); //<-- quotes
high = parseInt(high);
low = parseInt(low);
if (low && high) { //<-- missing parentheses
const randomNumber = Math.floor(Math.random() * (high - low + 1)) + low;
console.log(`An random number between ${high} and ${low} is ${randomNumber}`); //<-- template strings
} else {
console.log("Your input is not a number.Try again."); //<--- quotes
}