Skip to content

finished #21

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 2 commits 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
136 changes: 134 additions & 2 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,41 @@
* @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.
* @param {number} x
* @param {number} y
* @return {number} the sum
*/
function add(x,y){
var sum= x + y;
return sum;
}


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

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


/**
* Multiplies two numbers.
Expand All @@ -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.
Expand All @@ -50,13 +74,22 @@
* @return {number} the quotient
*/

function divide(x,y) {
var quotient= x / y;
return quotient;
}

/**
* Multiplies a number by itself.
* @param {number} x, number to be squared
* @return {number} squared
*/

function square(x) {
var squared = Math.pow(x,2);
return squared;
}


/**
* Performs a mathematical operation on two numbers.
Expand All @@ -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`.
Expand All @@ -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`.
Expand All @@ -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.
Expand All @@ -91,6 +157,9 @@
* @return {boolean} the numbers are equal
*/

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

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

function maximum(x,y) {
var largest = Math.max(x,y);

return largest;
}

/**
* Returns true if `n` is even.
* @param {number} n
* @return {boolean} the number is even
*/

function isEven(n){
if(n % 2 == 0){
return true;
}
}


/**
* Returns true if `n` is odd.
* @param {number} n
* @return {boolean} the number is odd
*/

function isOdd(n){
if(n % 2 !== 0){
return true;
}
}


/**
* Returns a letter grade.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -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;
}