From 77cbe1d3bde00f77dfe11786b248c222685bfaf8 Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 19 Jan 2017 16:45:48 +0530 Subject: [PATCH] all done for javascripting --- accessing-array-values.js | 2 ++ array-filtering.js | 5 +++++ array-program.js | 2 ++ for-loop.js | 7 +++++++ fruit-length.js | 8 ++++++++ function-arguments.js | 4 ++++ functions.js | 4 ++++ looping-through-arrays.js | 5 +++++ num-to-string.js | 5 +++++ numbers.js | 4 ++-- object-properties.js | 4 ++++ objects.js | 12 ++++++++++++ revising-string.js | 6 +++--- rounding-numbers.js | 6 +++--- scope.js | 18 ++++++++++++++++++ 15 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 accessing-array-values.js create mode 100644 array-filtering.js create mode 100644 array-program.js create mode 100644 for-loop.js create mode 100644 fruit-length.js create mode 100644 function-arguments.js create mode 100644 functions.js create mode 100644 looping-through-arrays.js create mode 100644 num-to-string.js create mode 100644 object-properties.js create mode 100644 objects.js create mode 100644 scope.js diff --git a/accessing-array-values.js b/accessing-array-values.js new file mode 100644 index 0000000..795a41d --- /dev/null +++ b/accessing-array-values.js @@ -0,0 +1,2 @@ +var foodsArray = ['apple', 'pizza', 'pear']; +console.log(foodsArray[1]); \ No newline at end of file diff --git a/array-filtering.js b/array-filtering.js new file mode 100644 index 0000000..1a4313d --- /dev/null +++ b/array-filtering.js @@ -0,0 +1,5 @@ +var numbersArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +var filteredArray = numbersArray.filter(function isEven(element) { + return (element % 2) === 0; + }); +console.log(filteredArray); \ No newline at end of file diff --git a/array-program.js b/array-program.js new file mode 100644 index 0000000..6e524d3 --- /dev/null +++ b/array-program.js @@ -0,0 +1,2 @@ + var pizzaToppingsArray = ['tomato sauce','cheese','pepperoni']; + console.log(pizzaToppingsArray); \ No newline at end of file diff --git a/for-loop.js b/for-loop.js new file mode 100644 index 0000000..4dfeae3 --- /dev/null +++ b/for-loop.js @@ -0,0 +1,7 @@ + var total = 0 ,limit = 10; + for (var i = 0; i < limit; i++) { + + total+=i; + + } + console.log(total); \ No newline at end of file diff --git a/fruit-length.js b/fruit-length.js new file mode 100644 index 0000000..5d17108 --- /dev/null +++ b/fruit-length.js @@ -0,0 +1,8 @@ +var fruit = 'orange'; +var fruitNameLength = fruit.length; +if (fruitNameLength > 1) { + console.log('The fruit name has more than five characters.'); + } +else { + console.log('The fruit name has five characters or less.'); + } \ No newline at end of file diff --git a/function-arguments.js b/function-arguments.js new file mode 100644 index 0000000..a7dfc3a --- /dev/null +++ b/function-arguments.js @@ -0,0 +1,4 @@ +function math(number1, number2, number3) { + return (number2 * number3) + number1; +} +console.log(math(53, 61, 67)); \ No newline at end of file diff --git a/functions.js b/functions.js new file mode 100644 index 0000000..3436796 --- /dev/null +++ b/functions.js @@ -0,0 +1,4 @@ +function eat(food) { + return food + ' tasted really good.';; +} +console.log(eat('bananas')); diff --git a/looping-through-arrays.js b/looping-through-arrays.js new file mode 100644 index 0000000..b1a78e9 --- /dev/null +++ b/looping-through-arrays.js @@ -0,0 +1,5 @@ +var petsArray = ['cat', 'dog', 'rat']; +for (var i = 0; i < petsArray.length; i++) { + petsArray[i] = petsArray[i] + 's'; +} +console.log(petsArray); \ No newline at end of file diff --git a/num-to-string.js b/num-to-string.js new file mode 100644 index 0000000..0c693fb --- /dev/null +++ b/num-to-string.js @@ -0,0 +1,5 @@ +var demoNum = 128; +demoNumString = demoNum.toString(); +console.log(demoNumString); +var numToStringLength = demoNumString.length; +//console.log(numToStringLength); \ No newline at end of file diff --git a/numbers.js b/numbers.js index 574fcc9..21b197f 100644 --- a/numbers.js +++ b/numbers.js @@ -1,2 +1,2 @@ -var example = 123456789; -console.log(example); +var demoNum = 123456789; +console.log(demoNum); diff --git a/object-properties.js b/object-properties.js new file mode 100644 index 0000000..5e82505 --- /dev/null +++ b/object-properties.js @@ -0,0 +1,4 @@ +var foodObject = { + types: 'only pizza' +}; +console.log(foodObject.types); \ No newline at end of file diff --git a/objects.js b/objects.js new file mode 100644 index 0000000..9c2e45c --- /dev/null +++ b/objects.js @@ -0,0 +1,12 @@ +// var pizzaObject = { +// toppingsArray: ['cheese', 'sauce', 'pepperoni'], +// crustString: 'deep dish', +// servesCount: 2 +// }; + + var pizzaObject = { + toppings: ['cheese', 'sauce', 'pepperoni'], + crust: 'deep dish', + serves: 2 + }; +console.log(pizzaObject); \ No newline at end of file diff --git a/revising-string.js b/revising-string.js index 15c0506..bfbef26 100644 --- a/revising-string.js +++ b/revising-string.js @@ -1,3 +1,3 @@ -var example = 'pasta is wonderful'; - example = example.replace('pasta', 'pizza'); - console.log(example); \ No newline at end of file +var stringReplace = 'pasta is wonderful'; +stringReplace = stringReplace.replace('pasta','pizza'); +console.log(stringReplace); \ No newline at end of file diff --git a/rounding-numbers.js b/rounding-numbers.js index 07e3acd..9488da1 100644 --- a/rounding-numbers.js +++ b/rounding-numbers.js @@ -1,3 +1,3 @@ -var roundUp=1.5; -roundUp=Math.round(roundUp); -console.log(roundUp); \ No newline at end of file +var roundUp = 1.5; +roundUpNum = Math.round(roundUp); +console.log(roundUpNum); \ No newline at end of file diff --git a/scope.js b/scope.js new file mode 100644 index 0000000..8f66d11 --- /dev/null +++ b/scope.js @@ -0,0 +1,18 @@ +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; + + })(); + })(); + })(); + })(); \ No newline at end of file