Space Invaders: Conditional

Hi everyone,

I am coding Space Invaders: conditional.

Using this code:

let alien = isAlienAbove()

repeat(10){
if (alien = true){
shoot()
}
move()
}

Why it shoots also when no alien above?

Thanks for a hint.

How many times are you actually calling the isAlienAbove function?
What happens to the alien variable after you move?

Review the video: is alien = true doing a comparison or something else?

currently I call it 10 times, but now no matter. As it shoots even when no alien there.

I created this variable:

image

then I repeat 10 times that it should check if alien = true (it means if there is alien above). Then it should move. But it shoots even when no alien. Not sure why

Once you put a value into the variable, the value won’t change by using. This tells Jiki to check for an alien then put that result into a variable. The value inside the variable will be the same thing every time you check it until you tell Jiki to change it.

1 Like

Please go back to the video (If Statements - Jiki) at around 1:34. That will show your the correct comparison operator to use for “equals”

1 Like

hi @katerina23 you can check here the comparison operators

1 Like

Two meta notes for everyone:

  1. Concept pages are basically transcripts of videos and have images. Good for sharing (e.g. If Statements). All are fully visible in incognito (no locking)
  2. if(x = y) will give an error once my current deployment is done.
2 Likes

I have it, it didn’t work to me even when I used ===. But issue was with setting variable. The variable was set outside of loop, while it should have been setup within the loop. Seems my logic thinking needs an improvement :slight_smile:

2 Likes

Go back to Jeremy’s explanation of functions: a machine that can emit a piece of paper with a value written on it. No matter how many times you look at it, that piece of paper is going to have the same value. Unless you get the machine to give you a new piece of paper.

1 Like