diff --git a/functions.js b/functions.js index f06bcee..e80d1a9 100644 --- a/functions.js +++ b/functions.js @@ -4,20 +4,30 @@ * @return {string} the number as a string */ +function numberToString(n) { + return "" + n; + +} /** * Adds one to a given number. * @param {number} n * @return {number} */ - +function increase(n){ + n++; + return n; +} /** * Subtracts one from a given number. * @param {number} n * @return {number} */ - +function decrease(n){ + n--; + return n; +} /** * Adds two numbers. @@ -25,6 +35,10 @@ * @param {number} y * @return {number} the sum */ + function add(x,y){ + var sum= x + y; + return sum; + } /** @@ -34,6 +48,11 @@ * @return {number} the difference */ + function subtract(x,y){ + var difference = x - y; + return difference; + } + /** * Multiplies two numbers. @@ -42,6 +61,11 @@ * @return {number} the product */ + function multiply(x,y){ + var product = x * y; + return product; + } + /** * Divides the first number by the second. @@ -50,6 +74,10 @@ * @return {number} the quotient */ +function divide(x,y) { + var quotient= x / y; + return quotient; +} /** * Multiplies a number by itself. @@ -57,6 +85,11 @@ * @return {number} squared */ + function square(x) { + var squared = Math.pow(x,2); + return squared; + } + /** * Performs a mathematical operation on two numbers. @@ -67,6 +100,32 @@ * @return {number} the result */ +function calculate(operation, x, y) { + + var result=0; + + if (operation == "add") { + result = x+y; + console.log(x + " + " + y + " = " + result); + return result; + } + else if (operation == "subtract") { + result=x-y; + console.log(x + " - " + y + " = " + result); + return result; + } + else if (operation==="multiply") { + result=x*y; + console.log(x + " * " + y + " = " + result); + return result; + } + if (operation=="divide") { + result=x/y; + console.log(x + " / " + y + " = " + result); + return result; + } + } + /** * Returns true if `a` is greater than `b`. @@ -75,6 +134,10 @@ * @return {boolean} `a` is larger than `b` */ + function isGreaterThan(a,b) { + return a > b; + } + /** * Returns true if `a` is less than `b`. @@ -83,6 +146,9 @@ * @return {boolean} `a` is smaller than `b` */ +function isLessThan(a,b) { + return a < b; +} /** * Returns true if `a` and `b` are equal. @@ -91,6 +157,9 @@ * @return {boolean} the numbers are equal */ +function areEqual(a,b) { + return a === b; + } /** * Returns the smallest value of two numbers. @@ -99,6 +168,12 @@ * @return {number} the smallest number */ + function minimum(a,b){ + var smallest = Math.min(a,b); + + return smallest; + } + /** * Returns the largest value of two numbers. @@ -107,6 +182,11 @@ * @return {number} the largest number */ +function maximum(x,y) { + var largest = Math.max(x,y); + + return largest; +} /** * Returns true if `n` is even. @@ -114,6 +194,12 @@ * @return {boolean} the number is even */ +function isEven(n){ + if(n % 2 == 0){ + return true; + } +} + /** * Returns true if `n` is odd. @@ -121,6 +207,12 @@ * @return {boolean} the number is odd */ + function isOdd(n){ + if(n % 2 !== 0){ + return true; + } + } + /** * Returns a letter grade. @@ -134,6 +226,26 @@ * @return {string} the score represented as a letter grade */ +function letterGrade(score,total){ + var percent = Math.floor((score/total)*100); + + if (percent >= 90){ + return "A"; + } + else if(percent >= 80){ + return "B"; + } + else if(percent >= 70){ + return "C"; + } + else if(percent >= 60){ + return "D"; + } + else + return "F"; + +} + /** * Checks if a `restaurant` object has a `reviews` property. @@ -142,7 +254,16 @@ * @param {object} restaurant represents a restaurant object * @return {object} restaurant */ +function incrementReviews(restaurant){ + console.log(restaurant); + if(restaurant.reviews != undefined){ + restaurant.reviews++; + }else{ + restaurant.reviews = 1; + } + return restaurant; +} /** * Joins two strings with a space. @@ -151,6 +272,10 @@ * @return {string} joined the words joined with a space */ + function combine(word1,word2) { + var combined= word1 + " " + word2; + return combined; +} /** * Returns a circle object with the properties `circumference` and `area`. @@ -160,3 +285,10 @@ * @return {object} circle */ +function createCircle(radius) { + var circle = {}; + circle.circumference = 2 * Math.PI * radius; + circle.area = Math.PI * (radius * radius); + return circle; +} +