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
course content

Зміст курсу

Introduction to TypeScript

Introduction to TypeScript

1. TypeScript Fundamentals
2. Conditional Statements
3. Arrays
4. Loops
5. Functions

book
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!

1234567891011121314151617181920212223
let randomNumbers: (number | string)[] = []; // do not change the code below for (let i = 0; i < 15; i++) { let randomNumber: number = Math.floor(Math.random() * 100); // Generating a random number from 0 to 99 randomNumbers.push(randomNumber); } //do not change the code above for (let i = 0; i < ___; i++) { // Assert that randomNumbers[i] is a number before using the modulus operator let num = randomNumbers[i] as number; if (___) { randomNumbers[i] = '___' } else if (___) { ___ = 'Fizz' } else if (___) { ___ } } console.log(randomNumbers);
copy

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 7
We're sorry to hear that something went wrong. What happened?
some-alt