How do you create a custom variable?

#1

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

this.MyVariable === 1

var MyVariable === 1

Any help?

0 Likes

#2

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

#3

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

#4

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

#5

Thank you for your help!

1 Like

#6

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

#7

Thanks for the help!

1 Like