Span with if- urgent!

So s the task, we have the pic how it shouldlook like.
Alert and console cnt be

Maybe documentGetByID…? I tried this too

But problem is how to write if statement in there…looking in w3schools for syntax rules, ad cant find…

Look, shoul dbe right like that BUT WITH COLORED NUMBERS!!!

http://pastebin.com/fhvT6Gsu

red if greater blue if smaller…classes red and blue haveto be placed in head

How’s this for a stream of consciousness?

document.write('Var a: <span class="' + (a > 10 ? 'red' : 'blue') + '">' + a + '</span>');

It’s a terrible way of doing things, but that’s what your teacher is wanting you to do.

just a minte…must try…(tried to do right sth like this…)

You could go even worse without class styles, and embed them directly in like this:

document.write('Var a: <span class="color:' + (a > 10 ? 'red' : 'blue') + '">' + a + '</span>');

Uh, finally, god bless…

I dont understnad clearly the first half till first +

Yes, and we did all of the work for you here. If this pattern continues then it looks like you may end up failing any exams that come along.

At the very least, I hope that we have helped you to understand that there are a wide variety of ways to approach things, each with their own pros and cons.

I get both classes blue, I will check for speling…but this was ment, obviously

THANKS!!!

Would someone else like to provide an opinion on which is worse?

Choice A: Using hard-coded CSS color style names
Choice B: directly embedding the css into the HTML code

Please why does it come BEFORE +

<span class="’

What do you mean by “it”?

I am the bsolute beginner and we use w3schools , I just missed a little syntax tricks…
I canunderstand this:

(a > 10 ? ‘red’ : ‘blue’)

but I am not familiar with ’ and " before…

‘Var a: ’ + a + ‘

Why is there no ’ after 'var a: ?

It comes later in the code. Read the link I sent and you’ll see why the ’ doesn’t end where you think it should.

Thanks, I do understand
test ? expression1 : expression2

but not the rest , particularry 's and "s are confusing me

Single and double quotes are used to surround text, both of which do the same job as the other.

Back in the bad old days when we were directly coding the HTML and CSS content straight from the Javascipt code.

document.write('<p id="test" class="demo">Some sample text</p>');

Because double quotes were commonly used in HTML code to surround element attributes, it became common for JavaScript to use single quotes.

These days because better techniques are used, there’s much less need to embed HTML code directly into your JavaScript code, so the benefit of using single quotes is dying off.

Whichever set of quotes you choose to stick with, just try to be consistent with how you use them. When it comes to coding standards, consistency becomes quite valuable.

Huh…is that right now:

‘Var a: <span class="’ // first ‘…’ block

  • (a > 10 ? ‘red’ : ‘blue’)
  • ’ ">’ //second ‘…’ block
  • a
  • ‘’

In this particular example, there are quoted strings.

The first quoted string is easy to see, which is 'Var a: ’
The second quoted string is empty, using two single quotes together. This is different from a double quote.

Two single quotes: ‘’
Two double quotes: “”

The above code could have been written less confusingly with double quotes:

"Var a: " + a + ""

Or, the last part could be just as easily removed completely.

'Var a: ' + a