Tuesday, December 23, 2014

Tuesday, December 2, 2014

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<button onclick="myDOWFunction()">What day is it?</button>
<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="leap"></p>
<script>
alert(new Date().getFullYear());
isLeapYear(new Date().getFullYear()+2);
cars = ["BMW","Volvo","Saab","Ford"];
var i = 0;
var size=4;
var text = "";
while (cars[i]) {
    text += "<H"+size+">"+cars[i]+"</h"+size+">";
    i++;
    size--;
}
document.getElementById("demo").innerHTML = text;

function myFunction() {
    var person = prompt("Please enter your name", "Your name");
    
    if (person != null) {
        document.getElementById("demo1").innerHTML =
        "Hello " + person + "! How are you today?";
    }
}
function myDOWFunction() {
    var day;


    switch(new Date().getDay()) {
        case 0:
            day = "Sunday";
            break;
        case 1:
            day = "Monday";
            break;
        case 2:
            day = "Tuesday";
            break;
        case 3:
            day = "Wednesday";
            break;
        case 4:
            day = "Thursday";
            break;
        case 5:
            day = "Friday";
            break;
        case  6:
            day = "Saturday";
            break;
    }
    document.getElementById("demo2").innerHTML = "Tomorrow is " + day;
}
function isLeapYear(years)
{
var result;
    if (years % 400==0){
      result = true;
    }
    else if(years%100==0){
      result = false;
    }
    else if(years%4==0){
      result= true;
    }
    else{
      result= false;
    }
    

    if(result)
document.getElementById("leap").innerHTML = "Yes it is a leap year.";
else
document.getElementById("leap").innerHTML = "Yes it is NOT a leap year.";
    
}
</script>

</body>
</html>