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

418
Visualizações
How to use conditionals in While loop to replace numbers with strings? (JS)

The instructions of my challenge say this:

"Using a WHILE loop, write a function imAboutToExplodeWithExcitement which prints a countdown from n. When the countdown gets to 5, print 'Oh wow, I can't handle the anticipation!' When it's at 3, print 'I'm about to explode with excitement!' When the counter is finished, print 'That was kind of a let down'."

I have managed to solve the first part and print the string "That was kind of a let down" at the end of the countdown.

My issue is that I do not know how to use if/else conditionals to replace the numbers at certain iterations with the strings (at numbers 3 and 5).

I know it involves using conditionals but I do not know what such a phrase would look like at all.

Thank you.

function imAboutToExplodeWithExcitement(n){
    //declare variable countdown 
    let countDown = n 
  // using a while loop, decrement from the value of n to 0
  while( countDown >= 0) {
    console.log(countDown); 
    countDown--;
    // if-else statements to replace 3 and 5 with their respective strings... 
    if 
    }
    
  
  //print message marking the end of the countdown 
    console.log("That was kind of a let down.");
}   

imAboutToExplodeWithExcitement(10); // expected log 10, 9, 8, 7, 6, 'Oh wow, I can't handle the anticipation!', 4, I'm about to explode with excitement!', 2, 1, 'That was kind of a let down'
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I wrote this and it seems to work the way you want it! The output of this code prints the number 10 and goes all the way down to 0, but on numbers 5, 3, and 0, it replaces those numbers and prints out a specific string!

function imAboutToExplodeWithExcitement(n) {
  while (n >= 0) {
    if (n > 5) console.log(n)
    else if (n === 5) console.log(`Oh wow, I can't handle the anticipation!`)
    else if (n === 3) console.log(`I'm about to explode with excitement!`)
    else if (n === 0) console.log(`That was kind of a let down`)
    else if (n > 0) console.log(n)
    n--
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

function imAboutToExplodeWithExcitement(n){
  while(n){
    if(n === 5){
     console.log("Oh wow, I can't handle the anticipation!"); 
    }else if(n === 3){
     console.log("I'm about to explode with excitement!"); 
    }else{
     console.log(n);
    }
    n--;
  }
    console.log('That was kind of a let down');
}
about 4 years ago · Juan Pablo Isaza Relatório
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