Skip to content

finished #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@
* @return {string} the number as a string
*/

function numberToString(num){
return num + '';
}



/**
* Adds one to a given number.
* @param {number} n
* @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;
}


/**
Expand All @@ -25,6 +36,9 @@
* @param {number} y
* @return {number} the sum
*/
function add(x,y){
return x + y;
}


/**
Expand All @@ -34,6 +48,10 @@
* @return {number} the difference
*/

function subtract(x,y){
return x - y;
}


/**
* Multiplies two numbers.
Expand All @@ -42,6 +60,10 @@
* @return {number} the product
*/

function multiply(x,y){
return x * y;
}


/**
* Divides the first number by the second.
Expand All @@ -50,13 +72,21 @@
* @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(x){
return x * x;
}


/**
* Performs a mathematical operation on two numbers.
Expand All @@ -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`.
Expand All @@ -75,13 +127,20 @@
* @return {boolean} `a` is larger than `b`
*/

function isGreaterThan(a,b){
return a > b;
}


/**
* Returns true if `a` is less than `b`.
* @param {number} a
* @param {number} b
* @return {boolean} `a` is smaller than `b`
*/
function isLessThan(a,b){
return a < b;
}


/**
Expand All @@ -91,6 +150,11 @@
* @return {boolean} the numbers are equal
*/

function areEqual(a,b){
return a === b;
}



/**
* Returns the smallest value of two numbers.
Expand All @@ -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.
Expand All @@ -107,20 +175,32 @@
* @return {number} the largest number
*/

function maximum(x,y){
var z = Math.max(x,y);
return z;
}


/**
* 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.
Expand All @@ -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";
}
};


/**
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -160,3 +269,17 @@
* @return {object} circle
*/


function createCircle(radius){
var circle = {
area: (radius * radius * Math.PI),
circumference: (2 * radius * Math.PI)
};

return circle;

}