From 5ef5b0f51d8b6533afc9a85ecdf9aef25f181d85 Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 19:14:35 -0700 Subject: [PATCH 1/6] Exercise 2 complete --- functions.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/functions.js b/functions.js index f6278ec..f8cb1c5 100644 --- a/functions.js +++ b/functions.js @@ -1 +1,25 @@ // YOUR CODE HERE + + + + + + + + + + + + +### `sillySum(arr)` +// YOUR CODE HERE +var myArray=[1,4,5]; +var multi = 0; + + +for (var i = 0; myArray.length > i; i++){ + + multi += (myArray[i] * i); // I made syntax error here. because of () I spent hours! I better learn from it :) +} + +console.log(multi); From d3504cc00cccfb52d08a7dd4fe22b54b9b011ecf Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 19:37:31 -0700 Subject: [PATCH 2/6] Exercise 3 complete --- functions.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/functions.js b/functions.js index f8cb1c5..d862f48 100644 --- a/functions.js +++ b/functions.js @@ -23,3 +23,22 @@ for (var i = 0; myArray.length > i; i++){ } console.log(multi); + + +### `numSquare(max)` + +Create a function called `numSquare` that will return an array of all perfect square numbers up to, but not exceeding a max number. + +var myArray=[1,2,3,4]; +var square; +function numSquare(y){ + for (var i=0; i < myArray.length; i++){ // SYNTAX ERRORS! + if ( y < myArray[i]) { + square = myArray[i] * myArray[i]; + console.log(square); + } + else console.log("number is bigger"); +} +} + +numSquare(3); From 18f99e40a1ca1a95b17656e852887644089fbcd6 Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 19:43:51 -0700 Subject: [PATCH 3/6] Exercise 4 complete --- functions.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/functions.js b/functions.js index d862f48..9d270a3 100644 --- a/functions.js +++ b/functions.js @@ -42,3 +42,15 @@ function numSquare(y){ } numSquare(3); + +### `isPrime(num)` + +Create a function that returns true if the number passed in is a prime number and false if not. + +function isPrime(num){ + if (num % num ===0){ + return true; + + } else + return false; +} From 091a88a59c0e2d9a1e77a04f5fe8bf2ea490df74 Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 19:57:11 -0700 Subject: [PATCH 4/6] working on exercise 5 --- functions.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/functions.js b/functions.js index 9d270a3..2473256 100644 --- a/functions.js +++ b/functions.js @@ -54,3 +54,27 @@ function isPrime(num){ } else return false; } + +### `primes(max)` + +Using your `isPrime` function, create a function primes that will return an array of all prime numbers up to, but not exceeding a max number. + +// working on it +var ilter = [1,2,3,4]; +var ilter2 = []; +var ilter3=[]; +//for (i = 0; i < ilter.length; i++){} + +ilter.forEach(function isPrime(element){ + if (element % element === 0){ +ilter2.push(element); + + +} +else ilter3.push(element); + + + + }); +console.log(ilter2); +console.log(ilter3); From a7d2bc9f6adf70ca76b6e1291a9570eae6d4f830 Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 20:48:37 -0700 Subject: [PATCH 5/6] finishedn exercise 1-- 1 === true but 9 === false? --- functions.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/functions.js b/functions.js index 2473256..735f4a8 100644 --- a/functions.js +++ b/functions.js @@ -1,12 +1,19 @@ // YOUR CODE HERE +### `maxOrMin(num1, num2, max)` +Define a function `maxOrMin` that takes three parameters: two numbers and a boolean. Have it return the larger of the two numbers if the boolean is true, otherwise have it return the lesser of the numbers. +ffunction maxOrMin(x,y,z){ + if ( z == true){ + console.log("its true!"); + if ( x < y){ + return y; + } else return x; - - - - - + } + console.log("it's false"); +} +maxOrMin(6,4,true); From 28d145a2101217971e89c2586f6018baa461b77c Mon Sep 17 00:00:00 2001 From: ilterates Date: Wed, 16 Mar 2016 21:07:15 -0700 Subject: [PATCH 6/6] addad oush to numSquare function --- functions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions.js b/functions.js index 735f4a8..1cf3aff 100644 --- a/functions.js +++ b/functions.js @@ -37,17 +37,20 @@ console.log(multi); Create a function called `numSquare` that will return an array of all perfect square numbers up to, but not exceeding a max number. var myArray=[1,2,3,4]; +var squareArray=[]; var square; function numSquare(y){ for (var i=0; i < myArray.length; i++){ // SYNTAX ERRORS! if ( y < myArray[i]) { square = myArray[i] * myArray[i]; + squareArray.push(square); console.log(square); } else console.log("number is bigger"); } -} +console.log(squareArray); +} numSquare(3); ### `isPrime(num)`