PDA

View Full Version : Java Script Help



sandeep0592
02-16-2016, 10:43 PM
Hello guys. I am asking you for a huge favour today, since I have no clue how to use javascript and I need this urgent.


I'm looking for somone to code me a script that will do the following.

First off all, I am creating a rashid timer. I want it to display where rashid is in TEXT format, every day, and the days should switch at server save(10.00 CET GMT+1)

So basicly I want this to be coded.

On Mondays you can find him in Svargrond
On Tuesdays you can find him in Liberty Bay
On Wednesdays you can find him in Port Hope
On Thursdays you can find him in Ankrahmun
On Fridays you can find him in Darashia
On Saturdays you can find him in Edron
On Sundays you can find him in Carlin

So for example, if its monday now (23:43) it should say Svargrond on the text, and when it turns 10:00(server save) tommorow it should automaticlly switch to Liberty Bay, and the following day at serversave the text should switch to Port Hope.

I hope my explanation is good enough, thanks alot!


If possible, it would be awesome if you could let us use images instead of texts, that way we could pick any font we want etc. So basicly images change daily instead of text changing daily, thanks. :)

texmex47
02-18-2016, 03:53 AM
I'm not a pro, but this is like 99% done.
Not entirely sure if getUTCDay() and getUTCHours() is the correct way of doing it (it probably isn't!).
Using getDay() and getHours() would only get the user's local time though, so it can't be that.


<!DOCTYPE html>
<html>
<head>
<title>Rashid</title>
</head>
<body>

<div id="rashid-info">

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">
// Variables for date and text
var day = new Date().getUTCDay();
var hour = new Date().getUTCHours() + 1;
var rashidText = "";

// 0 = Sunday, 1 = Monday, etc.
var messages = [
"On Sundays you can find him in Carlin",
"On Mondays you can find him in Svargrond",
"On Tuesdays you can find him in Liberty Bay",
"On Wednesdays you can find him in Port Hope",
"On Thursdays you can find him in Ankrahmun",
"On Fridays you can find him in Darashia",
"On Saturdays you can find him in Edron"
];

// If hour is 00:00-09:59 CET go back one day
if (hour < 10) {
rashidText = messages[day-1];
} else {
rashidText = messages[day];
}

// Output the text to the div-element
$('#rashid-info').text(rashidText);
</script>
</body>
</html>


edit: also make a check if day=0 (sunday), and then go back to day=6 (saturday). -1 doesnt work on first one in array.

neinrar
02-22-2016, 03:58 PM
Why not use AJAX for this?