How do you create a custom variable?

How would you create a custom variable name? I tried using:

this.MyVariable === 1

var MyVariable === 1

Any help?

Hey! To create a custom variable in JavaScript you need to use one equal sign!

this.myVariable = 5

or

myVariable = 5

Triple equal signs are used to check if two items are equal to each other.

otherVariable === 5; // Does the otherVariable equal 5?

Let me know if this helps!

1 Like

Thanks for the help! One other question I have is, is there some sort of and function? For example:

if (this.HitTest(that)) and (this.MyVariable === 1) {
}

1 Like

Yes indeed!
But it’s written like:

if( this.hitTest(that) && this.myVariable ===1){

//Make stuff happen.

}

You use two ampersands as the “and”.
alternatively, if you’d like to have two or more conditions for something to run,
you use two pipes ||:

if( this.hitTest(that) && this.myVariable ===1 ||
this.hitTest(that) && this.myVariable ===5){

//Make stuff happen.

}

I’d highly recommend you to check out this website below!

https://www.w3schools.com/jsref/jsref_operators.asp

On this page in particular, you can read up on all the different types of operators in
javascript.

1 Like

Thank you for your help!

1 Like

here are a few things that may help (some are repeated):
===: equal to
=: assign as
!==: not equal to
<, >: less than and greater than
<=, >=: less than or equal to and greater than or equal to
&&: and
||: or
%: modulo (remainder after dividing 2 numbers)
hope this helps :slight_smile:

2 Likes

Thanks for the help!

1 Like