This challenge has undergone another revamp, mainly improving tests and simplifying the description from its last incarnation.
Challenge
Starter Code
var fear = fearGenerated(numPeeps, rainInInches, numSharks);
var fearMessage = function() {
// Insert conditional statements here
};
function confirmRide(confirmToGo){
return confirmToGo();
}
// Call confirmRide here
Walkthrough
Inside the fearMessage
function expression, use conditional statements to check the already-generated fear
value, and decide whether it is LOW or MEDIUM.
var fearMessage = function() {
// Insert conditional statements here
};
At this point you could glance down to see how to setup the conditionals, but even if you go through linearly you might setup something like this:
var fearMessage = function() {
if (fear == 'LOW') {
} else if (fear == 'MEDIUM') {
}
};
Inside each conditional statement, return a specific confirm message in the following formats...
Hopefully this part is fairly clear with the syntax highlighting. We want to return confirm()
the messages provided. First I updated the conditional statements:
var fearMessage = function() {
if (fear < 200) {
} else if (fear >= 200 && fear <= 300) {
}
};
Then we add the confirmation messages:
var fearMessage = function() {
if (fear < 200) {
return confirm("Fear Level: LOW\nStill wanna ride?");
} else if (fear >= 200 && fear <= 300) {
return confirm("Fear Level: MEDIUM\nThink you'll make it?");
}
};
Lastly, call the confirmRide
function and pass in the fearMessage
variable. Then assign the results of that function in a new variable called startRide
.
var startRide = confirmRide(fearMessage);
Solution
var fear = fearGenerated(numPeeps, rainInInches, numSharks);
var fearMessage = function() {
if (fear < 200) {
return confirm("Fear Level: LOW\nStill wanna ride?");
} else if (fear >= 200 && fear <= 300) {
return confirm("Fear Level: MEDIUM\nThink you'll make it?");
}
};
function confirmRide(confirmToGo){
return confirmToGo();
}
var startRide = confirmRide(fearMessage);
Feedback
Thanks so much to everyone for all the feedback. If you have any specific feedback for how we can improve the challenge then be sure to let us know! We've been making continual improvements to the challenge descriptions, code, hints, and error messages so that the challenges are much more usable and you can focus on the learning!
- Note Bijan originally wrote this, and I just modified it.