/    Sign up×
Community /Pin to ProfileBookmark

JS Question of logic

Hi,
I opened this discussion to discuss with you a question of logic in javascript to do with the output screen.
The problem is the following:

There are three colors red, yellow and green.
The red must appear five seconds after the page has loaded.
The yellow must appear 2 seconds after it appeared the red but must remain with the red.
The green should appear after 7/2 but after that the other colors have disappeared.
After that must start from the first two colors in a loop.

The question must be resolved only with javascript and html with no other frameworks.

Please let for examples if you can use jsfiddle or similar.

Thank you so much of your solutions.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JakubauthorFeb 05.2015 — The green should appear after 7 seconds and only when the other two are disappear. Sorry for the mistake.
Copy linkTweet thisAlerts:
@Troy_IIIFeb 05.2015 — Where is your code Jakub?
Copy linkTweet thisAlerts:
@JakubauthorFeb 05.2015 — So I asked this for a curiosity about people logic thinking in js. I invented the question for that purpose. Is not an exercise and it is just a way to understand how people thinking logically and how they can arrive on the same solution with different methods. Is just about math. So please answer my question if you know how please.

By the way one of the methods could be used is use if statements functions and setIntervals - setTimout functions.

By the way is a challenge for who wants to take it.
Copy linkTweet thisAlerts:
@TcobbFeb 06.2015 — A challenge to complete your homework? Who could resist that?

========== me, for one.
Copy linkTweet thisAlerts:
@JMRKERFeb 06.2015 — I, too, have a logic curiosity question which is not homework and I can supply no code,

but I thought I should ask for help ... How's this for a challenge?

A farmer must take a fox and a chicken across a river in a boat that will only hold two at a time ...
Copy linkTweet thisAlerts:
@Sup3rkirbyFeb 06.2015 — A farmer must take a fox and a chicken across a river in a boat that will only hold two at a time ...[/QUOTE]
I 'loled'.

The thing about the original question in this top is that there isn't any logic involved. Not mentally or programmatically. Creating this example in javascript would really be nothing more than timeouts running in a pattern.

But if I'm being really picky, based on the original two posts, there seems to be a flaw in the question. Perhaps there was a typo or misunderstanding but it is said that:

- The red light appears 5 seconds after the page loads

- The yellow light appears 2 seconds after the red light, and remains on with the red light (7 seconds after the page loads)

- The green light appears 7 seconds after the page loads(?) But only after the first two disappear

Unless you meant the green light appears 7 seconds after one of the other two (which was not specified). Otherwise the flaw is that this scenario is impossible. But that's just me being picky with your wording. Clarity in language will always be relevant to success.
Copy linkTweet thisAlerts:
@JakubauthorFeb 07.2015 — One solution could be this one using jquery http://jsfiddle.net/jakub41/20L73jsk/

Please let me know what you think and the idea is a traffic light and the next part if you want is just to ask some buttons to regulate the lights with speed on/off and blinking.... So I put my idea :-)
×

Success!

Help @Jakub spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...