Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Fixing the Speed Function | Section
JavaScript Fundamentals
SectionΒ 1. ChapterΒ 48
single

single

bookChallenge: Fixing the Speed Function

Swipe to show menu

Task

Swipe to start coding

Previously, you created a calcSpeed function that calculated the speed of a car using fixed values inside the function. Now you need to improve the function so that it can accept values from outside.

Your tasks:

  1. Remove the local variables distance and timeTaken from inside the function.
  2. Add two parameters named distance and timeTaken in the function definition.
  3. Calculate the speed using the formula:
    Speed = Distance / Time Taken
    
  4. Return the calculated speed.
  5. Call the function twice using the following arguments:
    • 1000, 120
    • 1200, 160

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 48
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt