Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,715 members, 7,820,496 topics. Date: Tuesday, 07 May 2024 at 03:55 PM

Please I Need Help Writing This Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please I Need Help Writing This Code (736 Views)

Help On This Code / A Test For Python Guys. What Will This Code Do? / Explain This Code And Get Commended (2) (3) (4)

(1) (Reply)

Please I Need Help Writing This Code by StevensJojo(f): 2:46pm On May 29, 2015
Hi guys,

I'm a digital marketer with a little knowledge of html and css.

Today I hit a brick wall. Iv got a task I need to execute but it's JavaScript- I'm clueless!

Here's the instructions I'm supposed to follow-

1. Code a JAvaScript

2. Put 3 blogpost urls in the JavaScript

3. Create a function that would open all the Web addresses in my browser

4. Make the function sleep for 3-4 minutes

5. When the JavaScript reaches the end, it'll automatically bounce and repeat.

Please help?!
Re: Please I Need Help Writing This Code by kudaisi(m): 4:37pm On May 29, 2015
Not necessarily the best method to go about it, but this should work.
<!DOCTYPE html>
<html>
<head>
<script>

var urls = [
"http://www.yahoo.com/",
"http://www.outlook.com/",
"http://www.gmail.com/"
];
console.log("test"wink;
var length = urls.length;
var i = 0
function getUrl(){
if(i==length - 1 ){i=0;}
return urls[i];
}

function openUrl(url){
console.log("Opening url: "+url);
//window.open(url, "_self"wink//curent page
//window.open(url, "_parent"wink;// parent fame
window.open(url, "_blank"wink//new window (default)
//window.open(getUrl(), "_top"wink;// replaces frameset
i++;
}

function sleep() {
setTimeout(function () {
openUrl(getUrl());
sleep();
}, 10000);
}

sleep();
</script>
</head>
<body>
</body>
</html>
Re: Please I Need Help Writing This Code by StevensJojo(f): 5:11pm On May 29, 2015
Thanks!
kudaisi:
Not necessarily the best method to go about it, but this should work.
<!DOCTYPE html>
<html>
<head>
<script>

var urls = [
"http://www.yahoo.com/",
"http://www.outlook.com/",
"http://www.gmail.com/"
];
console.log("test"wink;
var length = urls.length;
var i = 0
function getUrl(){
if(i==length - 1 ){i=0;}
return urls[i];
}

function openUrl(url){
console.log("Opening url: "+url);
//window.open(url, "_self"wink//curent page
//window.open(url, "_parent"wink;// parent fame
window.open(url, "_blank"wink//new window (default)
//window.open(getUrl(), "_top"wink;// replaces frameset
i++;
}

function sleep() {
setTimeout(function () {
openUrl(getUrl());
sleep();
}, 10000);
}

sleep();
</script>
</head>
<body>
</body>
</html>

(1) (Reply)

Who Has Seen Silicon Valley! Tvseries Here / Arduino Microcontroller Board Thread / Java Learner

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.