And I take it that if it's 10:21, it writes '4,' not 'in 4 minutes.' Is that right?
And I take it that if it's 10:21, it writes '4,' not 'in 4 minutes.' Is that right?
Aye. Everything was thinking that I wanted the page to refrech the page every nanosecond. Does that refresh every minute? Or can I even do it in the script? Do I need the <meta http-equiv="refresh"> tag?
Sorry, that's kind of advanced... it creates an anonymous function (one without a name), then calls it with the current minutes as an argument. It's equivalent to:Code:var leaves = (function(x) { var v = x % 5; return (v === 0 ? 0 : 5) - v; })((new Date()).getMinutes());... but obviously much shorter.Code:function f(x) { var v = x % 5; if(v === 0) return v; else return 5 - v; } var d = new Date(); var leaves = f(d.getMinutes());This is an example of the tertiary operator.Code:window.location.href = (leaves === 0 ? "shuttle.html" : "index.html");is equivalent to:Code:var a = b ? c : d;Code:var a; if(b) a = c; else a = d;No, it doesn't. Since the user is redirected immediately, there's no point... oh. Now I see what you were attempting with location.href = "index.html". Don't do this. Instead, try something like:Is there any way to make that update every minute...or does it already?Code:<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p> <script type="text/javascript"> var leaves = (function() { var v = (new Date()).getMinutes() % 5; return (v === 0 ? 0 : 5) - v; })(); function updateMinutes() { var l = leaves(); document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes"); } setInterval(updateMinutes, 60000); </script>Arrays are vital in Javascript.I never learned what an array was, all I learned was if...else and switch.No. What lead you to that conclusion?And I take it that if it's 10:21, it writes '4,' not 'in 4 minutes.' Is that right?Ugh! The original doesn't, but the one above will update the time every minute. You don't need <meta>.Everything was thinking that I wanted the page to refrech the page every nanosecond . Does that refresh every minute? Or can I even do it in the script? Do I need the <meta http-equiv="refresh"> tag?
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Yeah. I think the cause of the refreshing was
It should have beenCode:else { window.location="index.html" }Code:else { }
Yes, I said this. It should, in fact, have been:Code:
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Except now I get 'Welcome to SGB Airport. Next shuttle leaves in ?. ..'
Not if you wait a minuteYou want to call it once first:
Code:<p>Welcome to SGB Airport. Next shuttle leaves in <span id="nextshuttle">?</span>.</p> <script type="text/javascript"> var leaves = (function() { var v = (new Date()).getMinutes() % 5; return (v === 0 ? 0 : 5) - v; })(); function updateMinutes() { var l = leaves(); document.getElementById("nextshuttle").firstChild.nodeValue = l + (l === 1 ? " minute" : " minutes"); } setInterval(updateMinutes, 60000); updateMinutes(); </script>
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
... what message?
ImageShack doesn't like me.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
And it throws 4 more of those every minute.
Bookmarks