diff --git a/functions.js b/functions.js index f06bcee..0385477 100644 --- a/functions.js +++ b/functions.js @@ -4,20 +4,26 @@ * @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) { + return n + 1; +} /** * Subtracts one from a given number. * @param {number} n * @return {number} */ - +function decrease(n) { + return n -1; +} /** * Adds two numbers. @@ -25,7 +31,9 @@ * @param {number} y * @return {number} the sum */ - +function add(a,b) { + return a + b; +} /** * Subtracts the second number from the first. @@ -33,15 +41,18 @@ * @param {number} y * @return {number} the difference */ - - +function subtract(x,y) { + return x-y; +} /** * Multiplies two numbers. * @param {number} x * @param {number} y * @return {number} the product */ - +function multiply(x,y) { + return x * y; +} /** * Divides the first number by the second. @@ -49,14 +60,18 @@ * @param {number} y * @return {number} the quotient */ - +function divide(x,y) { + return x/y; +} /** * Multiplies a number by itself. * @param {number} x, number to be squared * @return {number} squared */ - +function square(n) { + return n * n; +} /** * Performs a mathematical operation on two numbers. @@ -66,15 +81,18 @@ * @param {number} y * @return {number} the result */ - - +function mathematical(x,y) { + +} /** * Returns true if `a` is greater than `b`. * @param {number} a * @param {number} b * @return {boolean} `a` is larger than `b` */ - +function isGreaterThan(a,b) { + return a>b; +} /** * Returns true if `a` is less than `b`. @@ -82,7 +100,9 @@ * @param {number} b * @return {boolean} `a` is smaller than `b` */ - +function isLessThan(a,b) { + return a= y ? x : y; +} /** * Returns true if `n` is even. * @param {number} n * @return {boolean} the number is even */ - +function isEven(n) { + return n % 2 === 0; +} /** * Returns true if `n` is odd. * @param {number} n * @return {boolean} the number is odd */ - +function isOdd(n) { + return n % 2 !== 0; +} /** * Returns a letter grade. @@ -133,7 +163,19 @@ * @param {number} total maximum possible score * @return {string} the score represented as a letter grade */ - +function letterGrade(score, total) { + var percent = score / total; + 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,15 +184,24 @@ * @param {object} restaurant represents a restaurant object * @return {object} restaurant */ - - +function incrementReviews(restaurant) { + if (restaurant.reviews) { + restaurant.reviews++; + } + else { + restaurant.reviews = 1; + } + return restaurant; +} /** * Joins two strings with a space. * @param {string} word1 * @param {string} word2 * @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`. @@ -159,4 +210,10 @@ * @param {number} radius * @return {object} circle */ - +function createCircle(radius) { + var circle = { + circumference: 2 * Math.PI *radius, + area: Math.PI * (radius * radius) + } + return circle; +}