user3368467
user3368467

Reputation: 13

What am I missing here? (Javascript screen.width)

I have no idea what I'm missing here. I want to make a javascript, that responds to screen resolution, but I can't get it to work. Any input?

<SCRIPT LANGUAGE="javascript">

if (screen.width <= 479) 
{document.write("Less tgab 479");}


if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}


if (screen.width <= 768 && <= 989)
{document.write("Between 768 and 989")}


if (screen.width >= 990)
{document.write("Above 990")}

</SCRIPT>

All help are appreciated.

Upvotes: 1

Views: 87

Answers (2)

Matt Greer
Matt Greer

Reputation: 62027

Your shorthand for the ands doesn't work, you have to explicitly write each condition out. Also you got the first condition backwards

from this:

if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}

to this:

if (screen.width >= 480 && screen.width < 768)
{document.write("Between 480 and 767")}

Upvotes: 0

piacente.cristian
piacente.cristian

Reputation: 777

This should work

if (screen.width <= 479) {document.write("Less tgab 479");}

if (screen.width >= 480 && screen.width <= 767) {document.write("Between 480 and 767")}

if (screen.width >= 768 && screen.width <= 989) {document.write("Between 768 and 989")}

if (screen.width >= 990) {document.write("Above 990")}

The problem was you had wrong conditions in the second and third if

screen.width >= 480 && screen.width<= 767

screen.width >= 768 && screen.width<= 989

Upvotes: 1

Related Questions