The FizzBuzz problem is a common programming task, often used in coding interviews. The task is to print the numbers from 1 to a given number, but for multiples of three print 'Fizz' instead of the number, and for the multiples of five print 'Buzz'. For numbers which are multiples of both three and five print 'FizzBuzz'.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution uses a for loop to iterate over the numbers from 1 to the given number. It uses the modulus operator to check if the current number is a multiple of 3, 5, or both. If the number is a multiple of both 3 and 5, it prints 'FizzBuzz'. If it's a multiple of only 3, it prints 'Fizz', and if it's a multiple of only 5, it prints 'Buzz'. If the number is not a multiple of 3 or 5, it simply prints the number.
use strict'
function fizzBuzz(number) {
for (let i = 1 ; i <= number ; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log('FizzBuzz');
} else if (i % 3 === 0) {
console.log('Fizz');
} else if (i % 5 === 0) {
console.log('Buzz');
} else {
console.log(i);
}
}
}
fizzBuzz(10);
If you have a HackerRank Certification test or a coding interview coming up, you can use CodeRankGPT to your advantage. It will assist you during your test and help ensure you get the certification or the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.