Skip to content
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

functions done #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions .tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ecmaVersion": 6,
"libs": [],
"loadEagerly": [],
"dontLoad": [
"node_modules/**"
],
"plugins": {
"doc_comment": true
}
}
123 changes: 104 additions & 19 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,76 @@
* @param {number} n
* @return {string} the number as a string
*/

let numberToString = function(n) {
return n.toString();
};

/**
* Adds one to a given number.
* @param {number} n
* @return {number}
*/

let increase = function(n) {
return n + 1;
};

/**
* Subtracts one from a given number.
* @param {number} n
* @return {number}
*/

let decrease = function(n) {
return n - 1;
};

/**
* Adds two numbers.
* @param {number} x
* @param {number} y
* @return {number} the sum
*/

let add = function(x, y) {
return x + y;
};

/**
* Subtracts the second number from the first.
* @param {number} x
* @param {number} y
* @return {number} the difference
*/

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

/**
* Multiplies two numbers.
* @param {number} x
* @param {number} y
* @return {number} the product
*/

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

/**
* Divides the first number by the second.
* @param {number} x
* @param {number} y
* @return {number} the quotient
*/

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

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

let square = function(x) {
return x * x;
};

/**
* Performs a mathematical operation on two numbers.
Expand All @@ -66,61 +82,92 @@
* @param {number} y
* @return {number} the result
*/


function calculate(str, x, y) {
if (str === "add") {
let add = x + y;
console.log(x + " + " + y + " = " + add);
return add;
} else if (str === "subtract") {
let subtract = x - y;
console.log(x + " - " + y + " = " + subtract);
return subtract;
} else if (str === "multiply") {
let multiply = x * y;
console.log(x + " * " + y + " = " + multiply);
return multiply;
} else if (str === "divide") {
let divide = x / y;
console.log(x + " / " + y + " = " + divide);
return divide;
}
}
/**
* Returns true if `a` is greater than `b`.
* @param {number} a
* @param {number} b
* @return {boolean} `a` is larger than `b`
*/

let isGreaterThan = function(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`
*/

let isLessThan = function(a, b) {
return a < b;
};

/**
* Returns true if `a` and `b` are equal.
* @param {number} a
* @param {number} b
* @return {boolean} the numbers are equal
*/

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

/**
* Returns the smallest value of two numbers.
* @param {number} x
* @param {number} y
* @return {number} the smallest number
*/

let minimum = function(x, y) {
return Math.min(x, y);
};

/**
* Returns the largest value of two numbers.
* @param {number} x
* @param {number} y
* @return {number} the largest number
*/

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

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

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

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

let isOdd = function(n) {
return Math.abs(n % 2) === 1;
};

/**
* Returns a letter grade.
Expand All @@ -133,7 +180,29 @@
* @param {number} total maximum possible score
* @return {string} the score represented as a letter grade
*/
function letterGrade(score, total) {
let grade = score / total * 100;
switch (true) {
case grade >= 90:
return "A";
break;

case grade >= 80:
return "B";
break;

case grade >= 70:
return "C";
break;

case grade >= 60:
return "D";
break;

default:
return "F";
}
}

/**
* Checks if a `restaurant` object has a `reviews` property.
Expand All @@ -142,15 +211,25 @@
* @param {object} restaurant represents a restaurant object
* @return {object} restaurant
*/

function incrementReviews(restaurant) {
if (restaurant.reviews >= 1) {
restaurant.reviews++;
} else if (restaurant.reviews === undefined) {
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
*/

let combine = function(word1, word2) {
let words = word1 + " " + word2;
return words;
};

/**
* Returns a circle object with the properties `circumference` and `area`.
Expand All @@ -160,3 +239,9 @@
* @return {object} circle
*/

function createCircle(radius) {
let circle = {};
circle.circumference = 2 * Math.PI * radius;
circle.area = Math.PI * radius * radius;
return circle;
}
Loading