Hello!
I had to input var a =windows.prompt() and then if the number is >10 have to color it red by class red , and if it is <10 have to color it class blue
Here is my code:
<head>
<head>
<style>
span.red{
color:red;
}
spam.blue{
color:blue;
}
</style>
</head>
<body>
<script>
var a = windows.prompt();
document.write("var a: " + a)
</script>
</body>
Please, how to combine spam with document.write()?
Iâve always seen long-time developers say âdonât use document.write after a page loads, because it will re-write the whole page, including the javascript.â
Best to use the DOM, after the page loads, for output.
Put all lines within a function and call the function in a window onload or document ready code.
Also, in your CSS, you accidentally typed SPAM instead of SPAN for the blue.
Youâre setting variable âaâ on a prompt, but I suspect that the rest of the code is running before the prompt is returned, so âaâ probably doesnât exist while the DOM is being written to.
UPDATE: Also, you have TWO opening tags.
UPDATE: AAAAAAAND, I just noticed that you named PARAGRAPH âdemoâ, but youâre setting the colors for SPAN.
UPDATE: AAAAAAAND, I just noticed that you typed âwindowS.promptâ when it should be âwindoW.promptâ.
Hello!
Many thanks- good news, it DOES WORK IN MOZILL TOO!
Please, just one question, for any interested: what chapters in tutorials, (any of them) are to learn thorowly to understand that completely?
Many thanks!!!
Youâd have to check the table of contents of the tutorial to know the answer to that question.
If this is for homework, then you might be turning in something that is more advanced than the teacher is ready to convey to the students. ESPECIALLY if the teacher is teaching you to use document.write. (shudder)
And for document.write(), it basically just spits whatever you pass into it onto the DOM. So since a span is just: <span>something</span>, you just do document.write("<span>something</span>").
The code I supplied has a conditional that only checks to see if the value is GREATER THAN 10 or LESS THAN OR EQUAL TO 10. If you need to keep the color unchanged if the value IS EQUAL TO 10, then you can certainly add another condition.
But the code I gave you does what you originally asked for (except for if the value == 10).
UPDATE: And you were correct⌠I tested it in FF and it worked, there, too.