diff --git a/accessing-array-values.js b/accessing-array-values.js new file mode 100644 index 0000000..1981ab9 --- /dev/null +++ b/accessing-array-values.js @@ -0,0 +1,2 @@ +const food = ['apple', 'pizza', 'pear']; +console.log(food[1]); diff --git a/array-filtering.js b/array-filtering.js new file mode 100644 index 0000000..0bc5583 --- /dev/null +++ b/array-filtering.js @@ -0,0 +1,5 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +const filtered = numbers.filter(function(number) { + return number % 2 === 0; +}); +console.log(filtered); diff --git a/arrays.js b/arrays.js new file mode 100644 index 0000000..1668294 --- /dev/null +++ b/arrays.js @@ -0,0 +1,2 @@ +const pizzaToppings = ['tomato sauce', 'cheese', 'pepperoni']; +console.log(pizzaToppings); diff --git a/for-loop.js b/for-loop.js new file mode 100644 index 0000000..cf3b4f1 --- /dev/null +++ b/for-loop.js @@ -0,0 +1,6 @@ +var total = 0; +const limit = 10; +for(var i = 0; i < limit; i++) { + total += i; +} +console.log(total); diff --git a/function-arguments.js b/function-arguments.js new file mode 100644 index 0000000..09b438a --- /dev/null +++ b/function-arguments.js @@ -0,0 +1,4 @@ +function math (a, b, c) { + return a + b * c; +} +console.log(math(53, 61, 67)); diff --git a/functions.js b/functions.js new file mode 100644 index 0000000..4cbb3ff --- /dev/null +++ b/functions.js @@ -0,0 +1,4 @@ +function eat (food) { + return food + ' tasted really good.'; +} +console.log(eat('bananas')); diff --git a/if-statement.js b/if-statement.js new file mode 100644 index 0000000..65b9d8c --- /dev/null +++ b/if-statement.js @@ -0,0 +1,7 @@ +const fruit = 'orange'; +if(fruit.length > 5) { + console.log('The fruit name has more than five characters.'); +} +if(fruit.length <= 5) { + console.log('The fruit name has five characters or less.'); +} diff --git a/introduction.js b/introduction.js new file mode 100644 index 0000000..e921523 --- /dev/null +++ b/introduction.js @@ -0,0 +1 @@ +console.log('hello'); diff --git a/looping-through-arrays.js b/looping-through-arrays.js new file mode 100644 index 0000000..2f9735b --- /dev/null +++ b/looping-through-arrays.js @@ -0,0 +1,5 @@ +var pets = ['cat', 'dog', 'rat']; +for(let i = 0; i < pets.length; i++) { + pets[i] += 's'; +} +console.log(pets); diff --git a/number-to-string.js b/number-to-string.js new file mode 100644 index 0000000..97e4099 --- /dev/null +++ b/number-to-string.js @@ -0,0 +1,3 @@ +var n = 128; +n = n.toString(); +console.log(n); diff --git a/numbers.js b/numbers.js new file mode 100644 index 0000000..d02eead --- /dev/null +++ b/numbers.js @@ -0,0 +1,2 @@ +const example = 123456789; +console.log(example); diff --git a/object-properties.js b/object-properties.js new file mode 100644 index 0000000..1971b5c --- /dev/null +++ b/object-properties.js @@ -0,0 +1,4 @@ +const food = { + types: 'only pizza' +}; +console.log(food.types); diff --git a/objects.js b/objects.js new file mode 100644 index 0000000..15b098f --- /dev/null +++ b/objects.js @@ -0,0 +1,6 @@ +var pizza = { + toppings: ['cheese', 'sauce', 'pepperoni'], + crust: 'deep dish', + serves: 2 +}; +console.log(pizza); diff --git a/revising-strings.js b/revising-strings.js new file mode 100644 index 0000000..37d5f72 --- /dev/null +++ b/revising-strings.js @@ -0,0 +1,3 @@ +var pizza = 'pizza is alright'; +pizza = pizza.replace('alright', 'wonderful'); +console.log(pizza); diff --git a/rounding-numbers.js b/rounding-numbers.js new file mode 100644 index 0000000..a59dc60 --- /dev/null +++ b/rounding-numbers.js @@ -0,0 +1,3 @@ +const roundUp = 1.5; +const rounded = Math.round(roundUp); +console.log(rounded); diff --git a/scope.js b/scope.js new file mode 100644 index 0000000..4c349a7 --- /dev/null +++ b/scope.js @@ -0,0 +1,21 @@ +var a = 1, b = 2, c = 3; + + (function firstFunction(){ + var b = 5, c = 6; + + (function secondFunction(){ + var b = 8; + console.log("a: "+a+", b: "+b+", c: "+c); + + (function thirdFunction(){ + var a = 7, c = 9; + + (function fourthFunction(){ + var a = 1, c = 8; + + })(); + })(); + })(); + })(); + +// we want output: "a: 1, b:8, c:6" diff --git a/strings.js b/strings.js new file mode 100644 index 0000000..b6c5787 --- /dev/null +++ b/strings.js @@ -0,0 +1,2 @@ +const someString = 'this is a string'; +console.log(someString); diff --git a/variables.js b/variables.js new file mode 100644 index 0000000..0789b51 --- /dev/null +++ b/variables.js @@ -0,0 +1,2 @@ +const example = 'some string'; +console.log(example);