8. Timely Matters (Building a website from scratch)

non-track-course
code-year

#1

url to course: https://www.codecademy.com/courses/websites-r-fun/0/1



Here is the error I'm getting.

Oops, try again. You must define getGreeting to pass the test!

The js code is:

 window.onload = function() {
              var date = new Date();
              date = date.toTimeString();
              var getGreeting = function() {
              document.getElementById("greeting").innerHTML = "<p>It is "+date+".</p>";
              }
             getGreeting();
           }

It works but I keep getting the error so I can't move forward. Any help would be appreciated.


#2

@pdrunk

Try it by using

<script>
    function getGreeting() {
        var date = new Date();
        date = date.toTimeString();

        document.getElementById("greeting").innerHTML = 
                       "<p>It is "+date+".</p>";
       }

    window.onload = getGreeting;
</script>

#3

I'm now trying this since what you gave me above said that the date was undefined.

var date = new Date();
date = date.toTimeString();

function getGreeting() {
     var greeting = document.getElementById("greeting:).innerHTML = "<p>It is "+date+".</p>"
     return greeting;
}

window.onload = getGreeting;

And it gives me the error that it doesn't change the time when it is hit again. But it does.


#4

I meant.

function getGreeting() {
     var greeting = document.getElementById("greeting").innerHTML = "<p>It is "+date+".</p>"
     return greeting;
}

#5

Solved it.

var i = new Date();
i = i.toTimeString();

function getGreeting(date){
    var greeting = document.getElementById("greeting").innerHTML="<p>It is "+date+".</p>";
    return greeting;
    }

window.onload = function(){
    getGreeting(i);
}

#6

@pdrunk,
Could you provide the FULL code including the script-Tag's


#7

I actually provided the whole code on script.js


#8

@pdrunk,
I do not have access to your script.js....


#9

The part I put in the area above is the whole script and the only script used for the exercise.

For it again,

var i = new Date();
i = i.toTimeString();

function getGreeting(date){
    var greeting = document.getElementById("greeting").innerHTML="&lt;p&gt;It is "+date+".&lt;/p&gt;";
    return greeting;
    }

window.onload = function(){
    getGreeting(i);
}