I am completely stuck

Ugh. I’m so new to all this, and I’m trying to get through the .html basics section. I loaded Atom, but it’s missing the far left-hand side project pane. How do I view that? Thank you in advance – amazing community xox

1 Like

Now I’m doubly embarrassed. It resolved. I think I’m all good! xox

1 Like

Hi
Having trouble displaying “a is greater than 5”. I’m using Atom. I tried using Firefox, Chrome, and Safari.
Any suggestions?
Cheers
Otto

 <script>

var textToDisplay = “Hello World”;
document.write("

" + textToDisplay + “

”); (This worked OK & showed "Hello World”)
          var a = 5;
          if(a > 5){

              document.write("<h2>a is greater than 5</h2>"); (Not OK did not display anything!)
          }
 </script>
1 Like

you have a = 5 and then

if(a > 5){
}

but if you insert instead of a value 5 you will have

if(5 > 5){
}

but this is not true. Your variable a needs to be less then 5 to show text

a = 4

if(a < 5){
}

This what I tried.

1 Like

Thanx for your quick reply.
It’s been resolved.
Cheers
Otto

1 Like

Hi Ivan,

this thread is a very nice offer of you,
Offering individual help is a great feature!

Under “Reading Assignments - Variables” in the quiz there was a question:

(10+22)%3

Which the result was “2”. I am not sure how one comes to this result. Can you someone please explain?

Thanks!

-Odi

2 Likes

% stands for the remainder.

(10+22) = 32

32%3

3 can be put 10x in 32 making 30 and will leave you with 2.

Cheers

1 Like

Thank you, that’s very helpful!

1 Like

Can you please help me with this, when installing Code::Block, when i run a project and try and execute any code, this comes up, can someone please help me please, its frustrating me very much…

1 Like

My browsers (Chrome, Firefox, MS Edge) crashes my computer when I try to write the Loops in Javascript user “for” instead of “while” . I took half of the day to research this in You Tube and found great simulations, tried them out, looked in W3Schools scenarios…but I am still stuck, when I launch with the browsers it freezes up the whole computer, regardless of which machine I use. In the meantime, here is the code, that I used from Ivan’s tutorial:

This is a perfect website
<h1>this is the title</h1>

<script>

var textToDisplay = "howdy";

for(var counter = 0; counter<3; counter+1) {
  document.write("<h2> counter is now" + counter +""+ textToDisplay+"</h2>");

    }


</script>
1 Like

I noticed that the code was cut off, here’s the whole code:

1 Like

I don’t use CodeBlocks but in error message is stating that you need to define debugger

This link will probably help you out:

I fixed it!!! Yea! This is what I did…

I changed the counter+1 to counter++ instead and it worked. I do have a question, why would Ivan’s demonstration work with counter+1?

I researched that the former doesn’t actually update the value of counter.

2 Likes

For the record:

counter += 1

Would also work.

1 Like

Thanks so much for your feedback. I did finally figure it out, LOL, as Ivan says, "all you have to do is research [Google] to find your answer.

~~Stephen

1 Like

Hello everybody.
Is it possible to program C++ on Mac?

1 Like

Hi guys,
I’m wondering if someone can explain the solution to the chess board exercise we did in chapter 2 of the eloquent java script text book.

The solution is as follows:

var size = 8

for(var x = 0; x < size; x++){

  var board = "";

    for(var y = 0; y < size; y++){
        if ((y+x) % 2 == 0){
          board += " ";
        }
  else{board+="#"}
  }
  console.log(board)
  }

What i’m trying to understand is how the program is alternating between the # and spaces.
Currently im reading it as the first iteration “x” = 0. X being less than 8 means we continue with the code and then “y” is = to 0. Because there is no remainder when you add “x” and “y”, then divide by 2 a space is added to the board.
Now in the next loop, “x” will = 1, so the code progresses and now “y” is also = 1. Adding these two and dividing by 2 also doesnt produce a remainder, so in my head another space should be added. yet it adds a #.

Obviously I’m reading the code incorrectly, if someone could be so kind as to explain to me it would be a big help!

1 Like

The if (y+x) % 2 == 0 will output a space for every even number including 0, a hash added for every odd number. Because anything perfectly divisible by 2 will have 0 remainder, this will alternate the pattern. 0 % x returns 0 the pattern then begins with 0 and since the x value doesn’t change on each iteration of the y you get the pattern.

You can try this out in your console but consider the first row, the y loop generates columns and the x loop is responsible for the entire row.

Inner Y for loop

Iter 1: x= 0; y = 0;
Iter 2: x= 0; y = 1;
Iter 3: x = 0; y = 2;

It isn’t until the 8th iteration of the y loop that it exits and the x takes its next step, and then we go with a new construction of the y reset to 0
Iter 1: x = 1; y = 0;
Iter 2: x = 1; y = 1;
Iter 3: x = 1; y = 2;

I hope this helps.

2 Likes