Welcome to the forum Alex.
Take a look at the OP and you'll see:
- An attempt to try the problem.
- A clear lack of understanding about the DOM.
- And, some kind of attempt to actually learn (or there wouldn't be a Math.random() * 3).
In your response, the OP is guided to a tutorial on DOM CSS and given guidance to 'find a pretty good idea'. I'm sorry, but when I fish, I like a little more guidance on how to actually knot the line onto the hook as opposed to a line amounting to, "get some line, a hook, a book and an idea."
Now, let's take a critical look at what I posted -- Actually, hold the presses! That's exactly what I wanted to the OP to do: "take a critical look".
It is well known that the best way, for most, of learning a foreign language is via immersion. I see no reason why that cannot work for coding as well.
My code provided:
- A probably-unfamiliar doctype for the OP.
- The answer to the question.
- Comments to guide along the way -- without giving a full explanation.
- A bit more detail than was asked in the OP, requiring the OP to look at the code to truly achieve what was desired and in the process, learn more about how it all works.
- Inline JSON for variable declaration.
- Implicit type checking via a loop based on the assignment operator's return value.
- ... Well, I think you're getting the idea: An awful lot in but a few lines of code which will allow a number of opportunities to learn.
While some may think a link to read up on things is helpful; I oftentimes "show" in a manner which requires depth of thought to use and understand: Is not a picture worth 1000's words?
BTW: I really don't want to have this thread diverge from the OP and, while answering you, kept this post focused on the code provided and, therefore, on topic. If you really want to have a discussion about "how" people help, then please open a thread in the general discussion area and invite me to join.
__________________
Jeremy Miller
Please login or register to view this content. Registration is FREE
|