Click to See Complete Forum and Search --> : Java skript task HELP


nikitacg
02-02-2003, 06:03 AM
:confused:

I have to do this task if anyone can halp me this is task:

Task 2
Alert a random message depending on the time of day, followed by writing each word of the message on individual lines in the browser window.

Criteria
· Create 3 arrays (morning, afternoon and evening) Insert 4 multi-word sentences in each array
· Use the Math.random() method to generate a number
· Depending on the time of day, greet the user with the appropriate random message from the appropriate array
· Time of the day to be 00:00 – 11:59=morning. 12:00 – 18:00=afternoon, and the remainder=evening
· Pass the random message (string) as a value to function that incorporates a for loop . The loop will split the string at every space character and write each word on it’s own line within the browser window
· Make use of the date, string, Math and array objects
· Make use of a function and value passing



Morning
("Good Morning, what a great day for work","Just think, another day another dollar","Be cheerfull on this lovely moring,atleast pretend","Good Morning, now get to work","Remember to have your morning coffee"

Afternoon
("Good Afternoon, have u had lunch","Don't forget our daily afternoon sessions at 3:00pm","It's a nice afternoon isn't it","Shake away those afternoon blues")

Evening
("Good evening to you","In it for the overtime are we? Haha","Yor wife or husband must feel lonely","Reminder evening news at 10:pm")


THANK YOU !!!

Charles
02-02-2003, 07:19 AM
<script type="text/javascript">
<!--
var messages = [["Good Morning, what a great day for work","Just think, another day another dollar","Be cheerfull on this lovely moring,atleast pretend","Good Morning, now get to work","Remember to have your morning coffee", "I cheated"], ["Good Afternoon, have u had lunch","Don't forget our daily afternoon sessions at 3:00pm","It's a nice afternoon isn't it","Shake away those afternoon blues", "Someone else did my work for me"], ["Good evening to you","In it for the overtime are we? Haha","Yor wife or husband must feel lonely","Reminder evening news at 10:pm", "I should be expelled"]];

messages.getMessage = function () {
var time = 2;
var now = new Date ().getHours();
if (new Date().getHours < 12) {time = 0} else if (now < 18) {time = 1};
return this[time][Math.floor(Math.random() * 100) % this[time].length];
}

document.write('<p>', messages.getMessage(), '</p>');

document.write('<ol><li>', messages.getMessage().split(' ').join('</li><li>'), '</li></ol>');
// -->
</script>