0
JS Time's Up! Challenge Question
I'm having some trouble understanding the while loop, specifically with the JS Time's Up! challenge question: Write a program-timer, that will take the count of seconds as input and output to the console all the seconds until timer stops. Sample Input 4 Sample Output 4 3 2 1 0 My code: function main() { var seconds = parseInt(readLine(), 10) // Your code here while(seconds>=0); document.write(seconds + '<br />'); seconds--; } What am I missing?
10 Answers
+ 2
Cameron Please remove the semicolon on this line.
while(seconds >=0); {
Your while while loop should just look like this...
while(seconds>=0) {
console.log(seconds);
seconds--;
}
+ 2
It's just a syntax issue. Your while loop needs curly braces.
while(seconds>=0) {
console.log(seconds);
seconds--;
}
Also, you want to console.log(seconds) instead of writing to the document. You won't need a line break if you use console.log.
+ 1
function main() {
var seconds = parseInt(readLine(), 10)
// Your code here
while(seconds>=0); {
console.log(seconds);
seconds--;
}
}
+ 1
This Correct
function main() {
var seconds = parseInt(readLine(), 10)
// Your code here
while(seconds>=0){
console.log(seconds)
seconds--
}
}
0
function main() {
var seconds = parseInt(readLine(), 10)
// Your code here
while(seconds>=0); {
console.log(seconds);
seconds--;
}
}
Outputs: Execution Timed Out!
I've tried every iteration I could think of...just lost at this point.
0
Thanks, mate!
0
No worries 🙂
0
function main() {
var seconds = parseInt(readLine(), 10)
// my code
while (seconds >= 0) {
console.log(seconds);
seconds--;
}
}
Good Luck
0
Pls 🙏🙏 I'm trying too hard to solve python times up test but still my output is
3
2
1
Instead of 3
2
1
0
I'm putting my code as 👇
# take the number as input
number = int(input())
#use a while loop for the countdown
while number > 0:
print(number)
number = number - 1
0
# Pede o número de segundos como entrada
target_number = int(input())
# Usa um loop while para contar regressivamente do número alvo até 0
while target_number >= 0:
print(target_number)
target_number -= 1
print()