• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions●Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed○Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes○Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Arrow Functions

Mission: Backstage Toolkit

A backstage calculation can be written as an arrow function instead of a function declaration. Try three short calculations in script.js and check their results in the Console.

An arrow function is another way to store a function in a variable. For a single expression, the expression's value is returned automatically. You will meet function expressions and callbacks in more detail later; for now, compare this with the function declaration you just used.

Syntax variations

javascript
// Function declaration from the previous lesson
function traditionalAdd(a, b) { return a + b; }

// Arrow function — same result, stored in a variable
const add = (a, b) => a + b;

// Single parameter — parentheses optional
const double = n => n * 2;

// No parameters — empty parentheses required
const greet = () => "Hello!";

// Multi-line body — needs {} and explicit return
const classify = n => {
    if (n > 0) return "positive";
    if (n < 0) return "negative";
    return "zero";
};
console.log(add(2, 3), double(4)); // 5 8

For this exercise, use an arrow function for each calculation. Arrow functions also differ in how they handle this and constructors; those details matter later when you learn objects and classes.

For temperature conversion, Math.round(value * 10) / 10 rounds to one decimal place: scaling by ten makes the first decimal a whole number before rounding. You will explore Math in the built-ins module.

Your Task

  1. Declare square as an arrow function.
  2. Return n * n from square(n).
  3. Declare celsius as an arrow function.
  4. Convert Fahrenheit with (f - 32) * 5 / 9, rounded to one decimal via Math.round(value * 10) / 10.
  5. Declare isEven as an arrow function.
  6. Return boolean parity from isEven.
  7. Log 5² = 25 | 98°F = 36.7°C | 4 is even: true using all three functions.
Hint 1
1 / 3
HINT 1

Arrow function: const fn = (params) => expression;

HINT 2

Omit {} and return for single-expression arrow functions.

HINT 3

Arrow functions with one parameter don't need parentheses: n => n * 2.

Loading editor…
Press Run to execute your code.
READY
intercourses
javascript