diff --git a/my-script.js b/my-script.js index 5ac970c..4bb9d92 100644 --- a/my-script.js +++ b/my-script.js @@ -22,45 +22,112 @@ const greeting = (name) => { * Write a function called `add` that returns the sum of two numbers */ + function add(a,b){ + add = a+b; + return add; +} /** * Write a function called `subtract` that returns the difference between two numbers */ + function subtract(a,b){ + subtract = a-b; + return subtract; + } /** * Write a function called `min` that returns the smaller of two numbers */ + function min(a, b){ + min=Math.min(a, b); + return min; +}; /** * Write a function called `max` that returns the larger of two numbers */ + function max(a, b){ + max=Math.max(a, b); + return max; +}; + /** * Write a function called `isEven` that takes a single value and * returns `true` if it is even and `false` if it is odd */ + function isEven(a){ + if(a % 2 == 0){ + return true; + } + else{ + return false; + } + + } + /** * Write a function called `isOdd` that takes a single value and * returns `false` if it is even and `true` if it is odd */ + function isOdd(a){ + if(a % 2 != 0){ + return true; + } + else{ + return false; + } + } /** * Write a function called `factorial` that takes a single integer and * returns the product of the integer and all the integers below it */ + function factorial(a){ + if (a == 0){ + return 1; + } + else { + return factorial(a-1)*a; + } + } /** * Write a function called `oddFactorial` that takes a single integer and * returns the product of the integer and all the integers below it, but * only if they are odd. If the starting number is even, don't include it. */ - +/* + function oddFactorial(a){ + if (a % 2==0){ + a-1; + return a; + } + if(a<=1){ + return 1; + } + else{ + (a-2)*a; + return a; + } + + return oddFactorial(a); + } +*/ + +function oddFactorial(a){ + for(i=1, b=1; i<= a; i=i+2){ + b=b*i; + + } + return b; +} /** * Write a function that solves the Chessboard exercise from chapter two, @@ -69,6 +136,26 @@ const greeting = (name) => { * a single string and return it at the end of the function */ + function chessboard(a){ + let dimenson=a; + let string=""; + + for(q=0; q