From b4df7096fad1a3bc6be1682b55c74558390bef6f Mon Sep 17 00:00:00 2001 From: LeeEnck Date: Tue, 12 Nov 2019 12:06:25 -0500 Subject: [PATCH 1/2] Did exercises --- my-script.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/my-script.js b/my-script.js index 5ac970c..04e03bf 100644 --- a/my-script.js +++ b/my-script.js @@ -21,46 +21,71 @@ const greeting = (name) => { /** * Write a function called `add` that returns the sum of two numbers */ - +function add(x,y) { + return x + y; +} /** * Write a function called `subtract` that returns the difference between two numbers */ - +function subtract(x,y) { + return x - y; +} /** * Write a function called `min` that returns the smaller of two numbers */ - +function min(x, y) { + return Math.min(x,y); +} /** * Write a function called `max` that returns the larger of two numbers */ - +function max(x, y) { + return Math.max(x,y); +} /** * 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(x) { +if (x % 2 == 0) { + return true; +}else (x % 2 != 0) + 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(x) { +if (x % 2 == 0) { + return false; +}else (x % 2 != 0) + return true; +} /** * 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(x) + factorial !== - factorial { + factorial = factorial ++; + } /** * 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(x) { + for (let ) +} /** * Write a function that solves the Chessboard exercise from chapter two, @@ -85,4 +110,3 @@ module.exports = { oddFactorial: typeof oddFactorial === 'function' ? oddFactorial : null, chessboard: typeof chessboard === 'function' ? chessboard : null, }; - From 2e2bb750b6431c4a9cb0ee1a2434b62901f136fe Mon Sep 17 00:00:00 2001 From: LeeEnck Date: Tue, 12 Nov 2019 13:44:56 -0500 Subject: [PATCH 2/2] finished factorial and chessboard --- my-script.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/my-script.js b/my-script.js index 04e03bf..6b6a13b 100644 --- a/my-script.js +++ b/my-script.js @@ -73,19 +73,23 @@ if (x % 2 == 0) { * 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(x) - factorial !== - factorial { - factorial = factorial ++; +const factorial = function(x) { + let product = 1; + + for (; x > 0; x --) { + product *= integer; } + return product; +}; /** * 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(x) { +const oddFactorial = function(x) for (let ) -} +}; /** * Write a function that solves the Chessboard exercise from chapter two, @@ -93,7 +97,19 @@ function oddFactorial(x) { * Instead of printing each line using `console.log()`, build the grid using * a single string and return it at the end of the function */ +const chessboard = function(size) { + let board = ''; + for (let count = 1; count <= 8; count++) { + if (count % 2 !==0) { + board = board + " # # # #" + '\n'; + } else { + board = board + "# # # # " + '\n'; + } + } + + return board; +} /******************************************* * DO NOT CHANGE ANYTHING BELOW THIS LINE!