Advertisement
CodaarX

module 4

Feb 11th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. In this challenge, you will test your knowledge of expressions and operators.
  3.  
  4. THE PROBLEM:
  5. In most countries, there is a speed limit that's enforced on highway and drivers
  6. are given a speeding ticket when they exceed the speed limit by some threshold.
  7.  
  8. For example, if the speed limit is 80mph(miles per hour) and the allowed
  9. threshold is 15% or 0.15 then a driver driving at 92mph will be driving at
  10. exactly the max limit and may be given a speeding ticket.
  11.  
  12. Your challenge is to complete the code below to determine whether or not a
  13. driver should get a speeding ticket. Good luck!
  14. */
  15.  
  16. // Don't touch the next line, we will cover functions in the next lesson.
  17. function speedingTicket(speed, threshold) {
  18.     // speed and threshold are variables that contain the speed(e.g 80) and
  19.     // threshold(e.g 0.1). You shoud not redeclare or update these variables.
  20.  
  21.     const limit = 80; // DON'T UPDATE THIS LINE
  22.  
  23.     // Task #1: Write an expression to calculate the maxSpeed
  24.     // Hint: If the speed limit is 80, and the threshold is 0.1.
  25.     // Then max speed will be 1.1 * 80 i.e (1 + 0.1) * 80.
  26.     // Alternatively, max speed can be calculated as 80 + (0.1 * 80)
  27.     const maxSpeed = limit + (1 * threshold); // OUR CODE HERE (approximately 1 line)
  28.  
  29.     // Task #2: Write the expression that assigns 'yes' to ticket if the speed
  30.     // is greater than or equal to the maxSpeed, and 'no' otherwise.
  31.     const ticket = speed >= maxSpeed? 'Yes' : 'No'; // YOUR CODE HERE (approximately 1 line)
  32.  
  33.     return ticket; // DON'T UPDATE THIS LINE
  34. }
  35.  
  36. // THIS IS FOR YOUR TESTING ONLY. WHEN YOU RUN THIS PROGRAM IT SHOULD PRINT 'yes'
  37. console.log(speedingTicket(120, 0.1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement