<body>
<p id="output">i need to learn!..and fast!</p>
</body>
JavaScript
/*create a date object*/
/*var myBday=new Date();
myBday.setFullYear(1982,5,23);*/
var isItAndrewMcloughlinBirthday = function () {
var myBirthday = new Date(1982, 5, 23);
var theinput = input("please enter you date of birth");
for (var dateA = new Date(); !myBirthday(dateA); dateA.setDate(dateA.getDate() + 1)) {
if (dateA.getMonth() == myBirthday.getMonth() && dateA.getDate() == myBirthday.getDate()) {
$("#output").text("happy birthday");
} else {
isItAndrewMcloughlinBirthday++;
}
}
};
// This is the right place for comparison function, but the loop isn't necessary for this question, that's for q3. You also should be returning a true/false, not writing an output like this. 4/6.
// You also kind of shoved q3 in here, and it's the right basic idea with that loop, so you get 1/2 on that.
var isTodayAndrewMcloughlinBirthday = function () {
isItAndrewMcloughlinBirthday(new Date());
};
// _almost_ perfect, you just need to write 'return' in front of the call. 5.5/6. This was an easy question to overestimate; it's really quite simple.
isItAndrewMcloughlinBirthday();
// i leached much of this scruipt below, but i am learning from it and making it hybrid to what i need.
var howManyDaysUntilAndrewsBirthday = function () {
today = new Date();
var myBday = new Date(today.getFullYear(), 5, 23);
if (today.getMonth() == 5 && today.getDate() > 23) myBday.setFullYear(myBday.getFullYear() + 1);
//Set 1 day in milliseconds
var one_day = 1000 * 60 * 60 * 24;
//Calculate difference btw the two dates, and convert to days
alert(Math.ceil((myBday.getTime() - today.getTime()) / (one_day)) +
" days left until myBday!");
};
// Yes! This code isn't quite going ot work, so I won't give the full bonus, but this is exactly the approach you were meant to take. Dates are silly complex to work with, and as all students were told this was a fully-open book test, so why not use someone...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.