Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

417
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!