Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Where am I going wrong in the following js code?

Write a JavaScript program to build a word play. The function wordPlay must take a number greater than 0 & lesser than 51 as its argument and return the output in the following format.

When the argument is :

  1. greater than 50, the function must return : Range is High
  2. lesser than 1, the function must return : Not Valid
  3. within the specified range : the function must iterate through all the numbers within the range, append each of them to a string with a white-space & return the same.
  4. However, when a number divisible by both 5 & 3 is encountered, "Jump" is appended to the string; when a number divisible only by 3 is encountered, "Tap" is appended to the string; when a number divisible only by 5 is encountered, "Clap" is appended to the string (refer to the console outputs)

function wordPlay(number){
    if (number>50){
        console.log("Range is High");
    }
    else if(number<1) {
        console.log("Not Valid");
    }
    else if(number<=1 && number>=50) {
        for(var i=1;i<=number;i++)
        {
            if(number%5===0 && number%3===0){
                console.log("Jump");
            }
            else if(number%5===0){
                console.log("Clap");
            }
            else if(n%3===0)
            {
                console.log("Tap");
            }
            else
            {
                console.log("number");
            }
        }
    }
}
console.log(wordPlay(16));

Code is not working why can someone help?

Output should be:

1 2 Tap 4 Clap Tap 7 8 Tap Clap 11 Tap 13 14 Jump 16

function wordPlay(num) {
  if (num < 1) return "Not Valid";
  if (num > 50) return "Range is High";

  let str = "";

  for (i = 1; i <= num; i++) {
      if (i % 15 === 0) str += " Jump";
      else if (i % 3 === 0) str += " Tap";
      else if (i % 5 === 0) str += " Clap";
      else str += ` ${i}`;
  }

  return str;
}

console.log(wordPlay(16));

It is said to append space before any integer|Tap|Clap|Jump

So the output will be

' 1 2 Tap 4 Clap Tap 7 8 Tap Clap 11 Tap 13 14 Jump 16'
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda