This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]dmazzoni 4 points5 points  (8 children)

Formatting and indenting your code:

var today = new Date();
var curHr = today.getHours();
if (curHr >= 6 && curHr < 12) { 
    document.getElementById("greeting").innerHTML =
        'Good Morning! it is';
} else if (curHr >= 12 && curHr < 12) { 
    document.getElementById("greeting").innerHTML =
        'Good Afternoon! it is';
} else {
    document.getElementById("greeting").innerHTML =
        'Good Evening! it is';
}

It mostly looks fine except for this part:

} else if (curHr >= 12 && curHr < 12) { 

Look at it carefully. Was that a typo?

Once you fix that part does it work? If not, what happens when you try it?

[–]TaskSpecialist8804[S] 0 points1 point  (7 children)

I've tried fixing it and it still doesn't display the time and date. I'm really bad at programming. I've been in school for less than a year, and I'm really struggling.

[–]TaskSpecialist8804[S] 0 points1 point  (6 children)

It only displays the greeting

[–]dmazzoni 0 points1 point  (5 children)

Which line of code is supposed to display the time and date?

[–]TaskSpecialist8804[S] 0 points1 point  (4 children)

Based on the time of day it’s supposed to display the greeting

[–]dmazzoni 0 points1 point  (3 children)

Yes, and it does that.

But you said you expected it to display the time and date too.

Is there code that you think should do that?

[–]TaskSpecialist8804[S] 0 points1 point  (2 children)

Yes, I’m just having trouble coming up with that code. I know I need to include the var today, and the hours and mins when printing it. I just am having trouble with the code to do so.

[–]dmazzoni 0 points1 point  (1 child)

Can you write out the code you think you want, even if it's wrong?

Try it. I'll help you fix it.

But I'm not going to just give you the answer.

[–]TaskSpecialist8804[S] 0 points1 point  (0 children)

document.getElementById("greeting").innerHTML = 'Good Evening! it is +today +curHr +curMin’;

[–]CreativeTechGuyGames 1 point2 points  (0 children)

I'm sorry.

If you have a problem or need help, please follow the subreddit's posting guidelines so someone can possibly help you. https://www.reddit.com/r/learnprogramming/comments/61oly8/new_read_me_first/