Continuing where we left off: JavaScript lesson number 2
All code on this post can be ran using Google Chrome Console. You can open the console like this: Windows: `Control + Shift + J` Mac: `Command + Option + J`
Now with mac support :')
When we left off we were discussing Variables, Constants, Functions, and Datatypes This time we will be focusing on If/Else, Comparitors, Arrays, and JSON
This all says an hour ago. Is Jay typing out an essay?
it should say 6 minutes ago....
he made this post 13 mins ago shad
Let's start with comparitors (wrong term for it, the correct term is operators) Comparing: > Greater Than >= Greater than or equal to < Less Than <= Less Than or equal to == Equal to === Equal to same data type != Does not equal !== Does not equal same data type && and || or ! not typeof Type of the input Operations: % Modulus, it divides and returns the remainder of the division + Addition, it adds both numbers, and combines strings together - It subtracts / Division * Multiplication ++ Increments a number -- Decrements a number = set's the value of something += Addition to the current value (or combining strings) -= Subtraction from the current value *= Multiplication from the current value /= Division from the current value %= Modulus from the current value
Any questions thus far?
What is "data type"?
Oh, and here's the link to the previous post for those who missed it https://questioncove.com/study#/updates/5a99be7a2117d6522969c000
A data type is the type of data, be it string, integer, boolean, function, array, or JSON
Any other questions?
No sir
To briefly explain a if statement: ```javascript if (conditon) { //code } ``` ```javascript if (conditon) { //code } else { //code } ``` ```javascript if (conditon) { //code } else if (condition) { //code } else { //code } ``` Alright, let's move onto actually putting those to use in examples Let's say we have this: ``` var x = 5; var y = 25; var z = x+y; //should be equal to 30 if (z == 30) { console.log('Evaled to true!'); } else { console.log('Evaled to false!'); } ```
You should see `Evaled to true!` in the console
Got it
Same!
nuts
Let's now move onto a example of || and && ``` var op1 = 2+3 == 5; //Evaluates to true var op2 = 50+25 == 75; //Evaluates to true var op3 = 5+10 == 14; //Evaluates to false if (op1 && op2 || op3) { console.log('True!'); } ``` this code adds a bunch of numbers, and compares them, op1 and op2 are true, but op3 is false, yet the if statement still evaluates to true, this is because it asks if op1 AND op2 are true, OR if op3 is true so it get's through Make sense?
Yes sir ^-^
Yes
Using your knowledge from both lessons, I want you to write a function that contains a if statement, and returns the value of a operation if it evaluates to false, otherwise output something else. Any questions on these instructions?
Done. In you faceeee.
Yos*
Welp. You copy+pasted what I had, you didn't need to change the comment, and it's not a function
Damn it.
>wait for ಠ_ಠ
Looks right to me. A++++ ~o-o~
It's not a function
Shall I post a solution?
Yeh
Ugh how do you make it not a function?
``` function homework(hello,world) { var result = hello+world; if (result == 10) { return result; } else { return false; } } ```
Did that clear things up?
no, wut is homework for and 10
homework is the name of the function 10 is just a random number
you would run it and eval it to true by running `homework(5,5)`
Oh okie
is dat da solution to the homework you gave?
Yeh that is the solution
A solution*
Join our real-time social learning platform and learn together with your friends!