Exercise 1.1: Arrow Functions
Level 1
Exercise 1: Function conversion: You have a function add
that takes two parameters and returns their sum. Convert it into an arrow function. For example: function add(a, b) { return a + b; }
.
Exercise 2: Arrow function without parameters: Create an arrow function named randomNumber
that takes no parameters and returns a random number between 0 and 100.
Exercise 3: Use of this
in arrow functions: Create a class Person
that has a name
property and a greet
function that uses an arrow function. The function should print a greeting that includes the person’s name. For example: console.log(`Hello, ${this.name}`);
.
Level 2
Exercise 4: Arrow function inside a loop: Create a function called printNumbers
that takes an array of numbers and uses a for
loop to print each number to the console using an arrow function.
Level 3
Exercise 5: Arrow function with setTimeout
: Create an arrow function that logs a message to the console after waiting 3 seconds.
⚠️ Important: Open the browser console (F12 or Ctrl+Shift+I) to see the results of the exercises and verify that they work correctly.