Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: FizzBuzz | Section
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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 26

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookChallenge: FizzBuzz

Swipe um das Menü anzuzeigen

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 26
some-alt