How do you count down from 10 to say 1 on java script?
You could use any number of loops. For, do, while. Are you familiar with any of the loops?
just the for and while
Well, if you start at 10 and so something while that is > then 0, the subtract one each time.... see how that works?
Thanks
Try something like this var count=30; var counter=setInterval(timer, 1000); //1000 will run it every 1 second function countDown() { count=count-1; if (count <= 0) { clearInterval(counter); //counter ended, do something here return; } //Do code for showing the number of seconds here } to show the results from the counter add the line to anywhere on the page <span id="countDown"></span>
That's a good point wildfalcon. How you implement it depends on what type if countdown is meant! If it is wanting to print 10 lines in reverse order or count 10 seconds will result in completely different code.
Thanks guys. Can you recommend software to code java. Im learning both java and lil bit of python on os x mavericks.
Here is a more complete version: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head><title>UOP- University of Phoenix</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <html> <body> <script> var count=30; var counter=setInterval(countDown, 1000); //1000 will run it every 1 second function countDown() { count=count-1; if (count <= 0) { clearInterval(counter); //counter ended, do something here document.getElementById("countDown").innerHTML="And we have lift off!!!"; return; } document.getElementById("countDown").innerHTML=count; //Do code for showing the number of seconds here } </script> <p id="countDown"></p> </body></html>
I use eclipse IDE. You can download and instal that for free.
One of the more common IDEs for Java is Eclipse: http://www.eclipse.org/ It will take a little getting used to, but it is one of the one pros use, so it can be useful to learn it.
thanks again guys. this program works.
Join our real-time social learning platform and learn together with your friends!