Conditional Execution If-Else (script not executing)

Hi Guys,

I’m trying to get the text “eyooo” and the text “between 10 and 100” to appear in my chrome browser page, but instead I always get a blank page. I made a small if-else condition in ATOM.

Do I have to install something to get the script tag to work?

Hello world
    <script>

    var displayText ("eyooo");
    document.write("<h1>" + displayText + "</h1>");

    var a = 5;
    var b = 10;
    var c = 17;
    var d = a + b + c;
    if (d > 100) {
      document.write("<h1> bigger than 100 </h1>");
    } elseif (100 > d > 10){
      document.write("<h2> between 10 en 100 </h2>");
    }
    else {
      document.write("<h3> smaller than 10 </h3>");
    }
  </script>

I notice a couple of syntax errors and one of your conditions needed adjusting.

<script>
    var displayText = "eyooo";
    document.write("<h1>" + displayText + "</h1>");

    var a = 5;
    var b = 10;
    var c = 17;
    var d = a + b + c;
    if (d > 100) {
      document.write("<h1> bigger than 100 </h1>");
    } else if (100 >= d && d >= 10){
      document.write("<h2> between 10 en 100 </h2>");
    }
    else {
      document.write("<h3> smaller than 10 </h3>");
    }
  </script>
1 Like

You’re right, thanks for checking @CompSciGuyIT !

I adjusted the errors but still no text appearing on the page.
(btw html and body tags are wrapped around the script tag)

Hey @jebel,

the code posted by @CompSciGuyIT should work. The HTML file is run by your browser so you don’t need to install any extensions in Atom. Atom is just an editor you can use but any text editor would work to write HTML files. Maybe your browser blocks scripts but i doubt that.

thanks @nflaig,

_** found it ! else if was written in one word, should be two words else if :slight_smile: _

**It has something do to with the elseif function, when I try the code in the console, it gives error msg
Uncaught SyntaxError: Unexpected token {

When I leave it out of the program and just do a simple if else, text appears on the page.