Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: FizzBuzz | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Essential TypeScript Basics for JavaScript Developers - 1768407373799

bookChallenge: 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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 26

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookChallenge: FizzBuzz

Glissez pour afficher le menu

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 26
some-alt