Created
August 17, 2016 22:37
-
-
Save airportyh/2cc080c4e80fb1bd930062f4a87ce0a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| JS Workshop | |
| */ | |
| // Variable assignment | |
| var name = "Jenn"; | |
| var age = 5; | |
| var sentence = name + " is " + age + " years old."; | |
| // if statements | |
| if (age >= 21) { | |
| var sentence3 = name + " is an adult."; | |
| } else if (age >= 13) { | |
| var sentence2 = name + " is a teenager."; | |
| } else { | |
| var sentence4 = "Unknown."; | |
| } | |
| // while loop (don't use for loops until you master the while loop!) | |
| var counter = 1; | |
| while (counter <= 5) { | |
| console.log('Hello, world!'); | |
| counter = counter + 1; | |
| } | |
| // strings | |
| var str = "Hello, I am a string"; | |
| var str2 = 'I am also a string'; | |
| var str3 = str.toUpperCase(); | |
| var char1 = str[0]; | |
| var length = str.length; | |
| var strings = str.split(','); | |
| var str4 = "ABC"; | |
| var str5 = 'DEF'; | |
| var combinedString = str4 + str5; | |
| // arrays | |
| var array = [1, 2, 3, 4, 5]; | |
| var lengthOfArray = array.length; | |
| var firstElementOfArray = array[0]; | |
| var fifthElementOfArray = array[4]; | |
| var i = 0; | |
| while (i < array.length) { | |
| console.log(array[i]); | |
| i = i + 1; | |
| } | |
| // or loop through a string | |
| // functions | |
| function hello() { | |
| console.log('Hello world'); | |
| } | |
| hello(); | |
| function helloTo(subject) { | |
| console.log('Hello ' + subject); | |
| } | |
| helloTo('Ahmad'); | |
| // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment