Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

422
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda