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 branch #29

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
117 changes: 117 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@
* @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 = n + 1;
return n;
}

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

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

/**
* Adds two numbers.
Expand All @@ -26,6 +37,10 @@
* @return {number} the sum
*/

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

/**
* Subtracts the second number from the first.
Expand All @@ -34,6 +49,10 @@
* @return {number} the difference
*/

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

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

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

/**
* Divides the first number by the second.
Expand All @@ -50,13 +73,22 @@
* @return {number} the quotient
*/

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

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

function square(x) {
var squ = x * x;
return squ;
}


/**
* Performs a mathematical operation on two numbers.
Expand All @@ -67,6 +99,24 @@
* @return {number} the result
*/

function calculate(operation, x, y) {
var total = 0;

if (operation === 'add'){
total = x + y;
console.log (x + ' + ' + y ' = ' + total);

}else if (operation === 'multiply'){
total = x * y;
console.log (x + ' * ' + y + ' = ' + total);

}else if (operation === 'divide'){
total = x / y;
console.log (x + ' / ' + y ' = ' + total);

}
return total;
}

/**
* Returns true if `a` is greater than `b`.
Expand All @@ -75,6 +125,9 @@
* @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 +136,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 +147,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 +158,9 @@
* @return {number} the smallest number
*/

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

/**
* Returns the largest value of two numbers.
Expand All @@ -107,20 +169,29 @@
* @return {number} the largest number
*/

function maximum (x, y) {
return Math.max(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.
Expand All @@ -134,6 +205,26 @@
* @return {string} the score represented as a letter grade
*/

function letterGrade(x, y){

var grade = divide (x, y);

if (grade >= .9) {
return 'A';
}else if (grade >= .8) {
return 'B';

}else if (grade >= .7) {
return 'C';

}else if (grade >= .6) {
return 'D';

}else{
return 'F';

}
}

/**
* Checks if a `restaurant` object has a `reviews` property.
Expand All @@ -143,6 +234,18 @@
* @return {object} restaurant
*/

function incrementReviews(x) {

if (x.reviews) {
x.reviews ++;

}else{
x.reviews = 1;

}

return x;
}

/**
* Joins two strings with a space.
Expand All @@ -151,6 +254,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`.
Expand All @@ -160,3 +266,14 @@
* @return {object} circle
*/

function createCircle(radius) {

var circle = {

area: Math.PI (radius * radius);
circumference: Math.PI * 2 * radius;
}

return circle;
}

Loading