J's Rhapsody

[Javascript]문제 1.5: Functions as Parameters, Arguments and Return Values 본문

IT/JAVASCRIPT

[Javascript]문제 1.5: Functions as Parameters, Arguments and Return Values

J's Rhapsody 2018. 1. 11. 13:14

Functions as Parameters, Arguments and Return Values

Well, it stands to reason that some people might not want to experience the Haunted Hickory House if the fear is significantly elevated on that day.

  1. Inside the fearMessage function expression, use conditional statements (e.g., ifelse if) to check the integer value of the fear variable, assigned on line 1, and decide whether its value is LOW or MEDIUM.

  2. For each fear range below we want to display a confirmation message with the corresponding message. We can return a call to the confirmfunction that has a single string argument containing the correct message.

For fear levels less than 200 (i.e., fear < 200):

Fear Level: LOW
Still wanna ride?

For fear levels from 200 through 300 inclusive (i.e., fear >= 200 && fear <= 300):

Fear Level: MEDIUM
Think you'll make it?

Note: You do not need to change the existing code that’s provided for you in the challenge editor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var fear = fearGenerated(numPeeps, rainInInches, numSharks);
 
var fearMessage = function() {
  // Insert conditional statements here
  if(fear < 200){
    return "Fear Level: LOW\n Still wanna ride?";
  }
  else if(fear >= 200 && fear <= 300){
    return "Fear Level: MEDIUM\nThink you'll make it?";
  }
};
 
function confirmRide(confirmToGo) {
  return confirmToGo();
}
 
// Call confirmRide with the fearMessage function
var startRide = confirmRide(fearMessage);
cs


Comments