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