Created
August 12, 2010 19:03
-
-
Save bohford/521502 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given the following javascript code: | |
function countdown (num) { | |
for (var i = 0; i <= num; i += 1) { | |
setTimeout(function () { | |
alert(num - i); | |
}, i * 1000); | |
} | |
} | |
countdown(5); | |
// The desired result is a countdown from 5 to 0 using alert messages. | |
// Explain why the code only alerts -1, then fix the code so it works as expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment