From e4724f007e5e6bd28b149780f101d6efb757a89f Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 10 Dec 2017 16:39:19 -1000 Subject: [PATCH 1/2] add easy stuff out of the way --- functions.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/functions.js b/functions.js index f06bcee..9c4deee 100644 --- a/functions.js +++ b/functions.js @@ -4,20 +4,29 @@ * @return {string} the number as a string */ +function numberToString(n) { + return "" + n; //need to change +}; /** * Adds one to a given number. * @param {number} n * @return {number} */ - +function increase(n){ + var i = n + 1; + return i; +} /** * Subtracts one from a given number. * @param {number} n * @return {number} */ - +function decrease(n){ + var i = n - 1; + return i; +} /** * Adds two numbers. @@ -25,6 +34,10 @@ * @param {number} y * @return {number} the sum */ + function add(x,y){ + var sum= x + y; + return sum; + } /** @@ -34,6 +47,11 @@ * @return {number} the difference */ + function subtract(x,y){ + var difference = x - y; + return difference; + } + /** * Multiplies two numbers. @@ -42,6 +60,11 @@ * @return {number} the product */ + function multiply(x,y){ + var product = x * y; + return product; + } + /** * Divides the first number by the second. @@ -50,6 +73,10 @@ * @return {number} the quotient */ +function divide(x,y) { + var quotient= x / y; + return quotient; +} /** * Multiplies a number by itself. @@ -57,6 +84,11 @@ * @return {number} squared */ + function square(x) { + var squared = Math.pow(x,2); + return squared; + } + /** * Performs a mathematical operation on two numbers. @@ -67,6 +99,10 @@ * @return {number} the result */ + function calculate(){ + + } + /** * Returns true if `a` is greater than `b`. @@ -75,6 +111,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 +123,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 +134,9 @@ * @return {boolean} the numbers are equal */ +function areEqual(a,b) { + return a === b; + } /** * Returns the smallest value of two numbers. @@ -99,6 +145,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 +159,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 +171,12 @@ * @return {boolean} the number is even */ +function isEven(n){ + if(n % 2 == 0){ + return true; + } +} + /** * Returns true if `n` is odd. @@ -121,6 +184,12 @@ * @return {boolean} the number is odd */ + function isOdd(n){ + if(n % 2 !== 0){ + return true; + } + } + /** * Returns a letter grade. @@ -134,6 +203,9 @@ * @return {string} the score represented as a letter grade */ +function letterGrade(){ + +} /** * Checks if a `restaurant` object has a `reviews` property. @@ -142,7 +214,9 @@ * @param {object} restaurant represents a restaurant object * @return {object} restaurant */ +function incrementReviews(){ +} /** * Joins two strings with a space. @@ -151,6 +225,9 @@ * @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 +237,7 @@ * @return {object} circle */ + function createCircle(){ + + } + From 09b38f94530257be4b91c70335a2aaa743f85a11 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 11 Dec 2017 03:42:09 -1000 Subject: [PATCH 2/2] add finshed --- functions.js | 79 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/functions.js b/functions.js index 9c4deee..e80d1a9 100644 --- a/functions.js +++ b/functions.js @@ -5,8 +5,9 @@ */ function numberToString(n) { - return "" + n; //need to change -}; + return "" + n; + +} /** * Adds one to a given number. @@ -14,8 +15,8 @@ function numberToString(n) { * @return {number} */ function increase(n){ - var i = n + 1; - return i; + n++; + return n; } /** @@ -24,8 +25,8 @@ function increase(n){ * @return {number} */ function decrease(n){ - var i = n - 1; - return i; + n--; + return n; } /** @@ -99,8 +100,30 @@ function divide(x,y) { * @return {number} the result */ - function calculate(){ +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; + } } @@ -203,10 +226,27 @@ function isEven(n){ * @return {string} the score represented as a letter grade */ -function letterGrade(){ +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. * If it does, increase the property's `reviews` value by 1. @@ -214,8 +254,15 @@ function letterGrade(){ * @param {object} restaurant represents a restaurant object * @return {object} restaurant */ -function incrementReviews(){ - +function incrementReviews(restaurant){ + console.log(restaurant); + + if(restaurant.reviews != undefined){ + restaurant.reviews++; + }else{ + restaurant.reviews = 1; + } + return restaurant; } /** @@ -226,7 +273,8 @@ function incrementReviews(){ */ function combine(word1,word2) { - return word1 + " " + word2; + var combined= word1 + " " + word2; + return combined; } /** @@ -237,7 +285,10 @@ function incrementReviews(){ * @return {object} circle */ - function createCircle(){ - - } +function createCircle(radius) { + var circle = {}; + circle.circumference = 2 * Math.PI * radius; + circle.area = Math.PI * (radius * radius); + return circle; +}