Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge (FizzBuzz) | Loops
Introduction to TypeScript

Challenge (FizzBuzz)Challenge (FizzBuzz)

Task

The classic problem is called FizzBuzz. The task is very simple: You are given an array of random numbers, and the code for generating the numbers is provided above; please do not modify that code. Your task is to replace the array elements according to the following conditions:

  • If a number is divisible by 3, replace it with 'Fizz';
  • If a number is divisible by 5, replace it with 'Buzz';
  • If a number is divisible by both 3 and 5, replace it with 'FizzBuzz'.

As a result, you should return an array of numbers and strings. You can check the hints and solutions if you have any difficulties with solving this problem. This way, you will better absorb the information and improve your skills. May the force be with you!

1. Your goal is to limit the number of iterations in the loop to the length of the array. To achieve this, you can use i < arrayName.length.
2. When the number is divisible evenly by 3, you need to replace the array element with Fizz. To do this, inside the if condition, you should check it using the following condition: array[i] % 3 == 0.
3. You need to do the same with other checks. In the second if block, you should check if the number is evenly divisible by 5.
4. To check two conditions at once, use condition_1 && condition_2.

Все було зрозуміло?

Секція 4. Розділ 7
course content

Зміст курсу

Introduction to TypeScript

Challenge (FizzBuzz)Challenge (FizzBuzz)

Task

The classic problem is called FizzBuzz. The task is very simple: You are given an array of random numbers, and the code for generating the numbers is provided above; please do not modify that code. Your task is to replace the array elements according to the following conditions:

  • If a number is divisible by 3, replace it with 'Fizz';
  • If a number is divisible by 5, replace it with 'Buzz';
  • If a number is divisible by both 3 and 5, replace it with 'FizzBuzz'.

As a result, you should return an array of numbers and strings. You can check the hints and solutions if you have any difficulties with solving this problem. This way, you will better absorb the information and improve your skills. May the force be with you!

1. Your goal is to limit the number of iterations in the loop to the length of the array. To achieve this, you can use i < arrayName.length.
2. When the number is divisible evenly by 3, you need to replace the array element with Fizz. To do this, inside the if condition, you should check it using the following condition: array[i] % 3 == 0.
3. You need to do the same with other checks. In the second if block, you should check if the number is evenly divisible by 5.
4. To check two conditions at once, use condition_1 && condition_2.

Все було зрозуміло?

Секція 4. Розділ 7
some-alt