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 trialjeffkorfanta98
3,645 PointsWhy am I getting a parse error?
var firstNumber = prompt("Please enter a number"); var secondNumber = prompt("Please enter another number"); firstNumber = parseInt(firstNumber); secondNumber = parseInt(secondNumber); function max(firstNumber, secondNumber) { If (firstNumber > secondNumber) { var result = firstNumber; return result;
} else if (firstNumber < secondNumber) { var result = secondNumber; return result; } else { alert("Your numbers are equal"); } } alert( result + " is the greater of the two numbers");
var firstNumber = prompt("Please enter a number");
var secondNumber = prompt("Please enter another number");
firstNumber = parseInt(firstNumber);
secondNumber = parseInt(secondNumber);
function max(firstNumber, secondNumber) {
If (firstNumber > secondNumber) {
var result = firstNumber;
return result;
}
else if (firstNumber < secondNumber) {
var result = secondNumber;
return result;
}
else {
alert("Your numbers are equal");
}
}
alert( result + " is the greater of the two numbers");
jeffkorfanta98
3,645 PointsThanks, but I'm still getting a parse error.
jeffkorfanta98
3,645 PointsNow I'm getting the following error message: "ReferenceError: Can't find variable: result
jeffkorfanta98
3,645 PointsI put the alert statement inside the function and now it works!
Katherine Ebel
43,799 PointsYes because since you defined result inside your function, you cannot access it outside of the scope of that function. You want to alert what is returned by calling that function.
2 Answers
Katherine Ebel
43,799 PointsI think you are getting the Reference Error because you are accessing the result variable outside of the function when you call the alert method. Move the last call to alert inside of the max function, and I think that should work... In the challenge you want to alert the result of calling your max function (for the second step).
Ben Myhre
28,726 Pointsyes.. this is an issue as well.
Ben Myhre
28,726 PointsIf
uncap that i
Katherine Ebel
43,799 PointsKatherine Ebel
43,799 PointsHi jeffkorfanta98. Change If to if in your max function, and see if that helps.