This lesson's interactive features are locked, please to keep using them
You're on assignment part 2/2 for this lesson.
In Python, a function must be defined before any code that executes it. But that's not so in JavaScript! As long as a function is defined somewhere in the file, it can be called even before the definition.
console.log(getLabel(3));
// prints 'awful'
function getLabel(numStars) {
if (numStars > 7) {
return "great";
} else if (numStars > 3) {
return "okay";
} else {
return "awful";
}
}
This works because JavaScript "hoists" the function declaration to the top of the file before the code is executed.