diff --git a/functions.js b/functions.js index f06bcee..de50f95 100644 --- a/functions.js +++ b/functions.js @@ -4,6 +4,11 @@ * @return {string} the number as a string */ + function numberToString(num){ + return num + ''; + } + + /** * Adds one to a given number. @@ -11,12 +16,18 @@ * @return {number} */ +function increase(num){ + return num + 1; +} /** * Subtracts one from a given number. * @param {number} n * @return {number} */ + function decrease(num){ + return num - 1; + } /** @@ -25,6 +36,9 @@ * @param {number} y * @return {number} the sum */ +function add(x,y){ + return x + y; +} /** @@ -34,6 +48,10 @@ * @return {number} the difference */ + function subtract(x,y){ + return x - y; + } + /** * Multiplies two numbers. @@ -42,6 +60,10 @@ * @return {number} the product */ + function multiply(x,y){ + return x * y; + } + /** * Divides the first number by the second. @@ -50,6 +72,10 @@ * @return {number} the quotient */ + function divide(x,y){ + return x / y; + } + /** * Multiplies a number by itself. @@ -57,6 +83,10 @@ * @return {number} squared */ + function square(x){ + return x * x; + } + /** * Performs a mathematical operation on two numbers. @@ -67,6 +97,28 @@ * @return {number} the result */ +var result; + var equation; + + function calculate (operation, x,y){ + if (operation === "add"){ + result = add(x,y); + equation = x + " + " + y + " = " + result; + }else if (operation === "subtract"){ + result = subtract(x,y); + equation = x + " - " + y + " = " + result; + }else if (operation === "multiply"){ + result = multiply(x,y); + equation = x + " * " + y + " = " + result; + }else if (operation === "divide"){ + result = divide(x,y); + equation = x + " / " + y + " = " + result; + } + + + console.log(equation); + return(result); + } /** * Returns true if `a` is greater than `b`. @@ -75,6 +127,10 @@ * @return {boolean} `a` is larger than `b` */ + function isGreaterThan(a,b){ + return a > b; + } + /** * Returns true if `a` is less than `b`. @@ -82,6 +138,9 @@ * @param {number} b * @return {boolean} `a` is smaller than `b` */ + function isLessThan(a,b){ + return a < b; + } /** @@ -91,6 +150,11 @@ * @return {boolean} the numbers are equal */ + function areEqual(a,b){ + return a === b; + } + + /** * Returns the smallest value of two numbers. @@ -99,6 +163,10 @@ * @return {number} the smallest number */ + function minimum(x,y){ + var z = Math.min(x, y); + return z; + } /** * Returns the largest value of two numbers. @@ -107,6 +175,11 @@ * @return {number} the largest number */ + function maximum(x,y){ + var z = Math.max(x,y); + return z; + } + /** * Returns true if `n` is even. @@ -114,6 +187,10 @@ * @return {boolean} the number is even */ + function isEven(n){ + return n % 2 === 0; + } + /** * Returns true if `n` is odd. @@ -121,6 +198,9 @@ * @return {boolean} the number is odd */ +function isOdd(n){ + return n % 2 !== 0; +} /** * Returns a letter grade. @@ -133,6 +213,20 @@ * @param {number} total maximum possible score * @return {string} the score represented as a letter grade */ + function letterGrade(score, total){ + var percentage = score/total * 100; + if (percentage < 60) { + return "F"; + } else if (percentage < 70) { + return "D"; + } else if (percentage < 80) { + return "C"; + } else if (percentage < 90) { + return "B"; + } else { + return "A"; + } +}; /** @@ -143,6 +237,17 @@ * @return {object} restaurant */ + function incrementReviews(restaurant){ + if(restaurant.reviews){ + restaurant.reviews += 1; + }else{ + restaurant.reviews = 1; + } + + return restaurant; + + } + /** * Joins two strings with a space. @@ -151,6 +256,10 @@ * @return {string} joined the words joined with a space */ + function combine(word1,word2){ + return word1 + " " + word2; + } + /** * Returns a circle object with the properties `circumference` and `area`. @@ -160,3 +269,17 @@ * @return {object} circle */ + + function createCircle(radius){ + var circle = { + area: (radius * radius * Math.PI), + circumference: (2 * radius * Math.PI) + }; + + return circle; + + } + + + +