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 trialAyrton Tavares
Full Stack JavaScript Techdegree Student 898 PointsNeed help - SyntaxError: Parse error
really lost with returning a specific value of an argument using a conditional statement.
function max (1,11) {
var largerNumber = 11;
var smallerNumber = 1;
if (parseInt(largerNumber) === 11) {
return largerNumber;
} else {
return smallerNumber;
}
}
1 Answer
Nick Trabue
Courses Plus Student 12,666 PointsWhen you're defining a function, you don't want to include the variables you are testing. The key is to make the function repeatable so that you can use it throughout your code. Think of the parameters a function takes as two variables that have not yet been defined.
function max(a, b) {
if (parseInt(a) > parseInt(b)) {
return a
} else {
return b
}
}
Now you'll be able to call that function elsewhere in your code knowing exactly what your outcome will be
var numberOne = 12
var numberTwo = 4
max(numberOne, numberTwo) // will return 12
max(numberTwo, numberOne) // will still return 12
As such, It's probably not a good idea to declare a larger number and a smaller number as a variable within that function because the function is pure and does not care which order you pass the numbers.
Ayrton Tavares
Full Stack JavaScript Techdegree Student 898 PointsAyrton Tavares
Full Stack JavaScript Techdegree Student 898 PointsThank you!