Skip to content

Js-Functions finished! #23

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
187 changes: 186 additions & 1 deletion functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,36 @@
*/


var number = 0;

function numberToString(number){
number = number.toString();
return number;
}
numberToString(4);

/**
* 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;

}


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

}


/**
Expand All @@ -33,6 +56,11 @@
* @param {number} y
* @return {number} the difference
*/
function subtract(x,y){
var diff = x-y;
return diff;

}


/**
Expand All @@ -41,6 +69,11 @@
* @param {number} y
* @return {number} the product
*/
function multiply(x,y){
var mult = x*y;
return mult;

}


/**
Expand All @@ -49,13 +82,23 @@
* @param {number} y
* @return {number} the quotient
*/
function divide(x,y){
var div = x/y;
return div;

}


/**
* Multiplies a number by itself.
* @param {number} x, number to be squared
* @return {number} squared
*/
function square(x){
var squ = x*x;
return squ;

}


/**
Expand All @@ -66,6 +109,30 @@
* @param {number} y
* @return {number} the result
*/
function calculate(operation, x, y) {
var number;
var x;
var y;

if(operation === "add"){
number = x+y;
console.log(x + " + " + y + " = " + number);
}
else if(operation === "subtract"){
number = x-y;
console.log(x + " - " + y + " = " + number);
}
else if(operation === "multiply"){
number = x*y;
console.log(x + " * " + y + " = " + number);
}
else if(operation === "divide"){
number = x/y;
console.log(x + " / " + y + " = " + number);
}
return number;
}
calculate("add",1,2);


/**
Expand All @@ -74,14 +141,33 @@
* @param {number} b
* @return {boolean} `a` is larger than `b`
*/
function isGreaterThan(a, b){
if (a > b){
console.log("a" + " is larger than " + "b");
return true;
}
else{
return false;
}

}

/**
* 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){
if (a < b){
console.log("a" + " is smaller than " + "b");
return true;
}
else{
return false;
}

}


/**
Expand All @@ -90,6 +176,16 @@
* @param {number} b
* @return {boolean} the numbers are equal
*/
function areEqual(a, b){
if (a === b){
console.log("the numbers are equal");
return true;
}
else{
return false;
}

}


/**
Expand All @@ -98,6 +194,17 @@
* @param {number} y
* @return {number} the smallest number
*/
function minimum(x,y){
if(x<y){
console.log("the smallest number");
return x;
}
else{
console.log("the smallest number");
return y;
}

}


/**
Expand All @@ -106,20 +213,55 @@
* @param {number} y
* @return {number} the largest number
*/
function maximum(x,y){
if(x>y){
console.log("the largest number");
return x;
}
else{
console.log("the largest number");
return y;
}

}


/**
* Returns true if `n` is even.
* @param {number} n
* @return {boolean} the number is even
*/
function isEven(n){
if(n%2 === 0){
console.log("the number is even");
return true;
}
else{
return false;
}



}


/**
* Returns true if `n` is odd.
* @param {number} n
* @return {boolean} the number is odd
*/
function isOdd(n){
if(n%2 != 0){
console.log("the number is odd");
return true;
}
else{
return false;
}



}


/**
Expand All @@ -133,6 +275,26 @@
* @param {number} total maximum possible score
* @return {string} the score represented as a letter grade
*/
function letterGrade(score, total){
var grade = (score/total)*100;
if (grade >= 90){
return "A";
}
else if(grade <90 && grade >= 80){
return"B"
}
else if(grade <80 && grade >= 70){
return"C"
}
else if(grade <70 && grade >= 60){
return"D"
}
else if(grade <60 && grade >= 0){
return"F"
}


}


/**
Expand All @@ -142,14 +304,29 @@
* @param {object} restaurant represents a restaurant object
* @return {object} restaurant
*/

function incrementReviews(restaurant){
if (restaurant.reviews){
restaurant.reviews++;
}
else{
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
*/
function combine(word1, word2){
var join = word1 + " "+word2;
console.log(join);
return join;


}


/**
Expand All @@ -159,4 +336,12 @@
* @param {number} radius
* @return {object} circle
*/
function createCircle(radius){
var circle = {
circumference:2*Math.PI*radius,

area:Math.PI*(radius*radius)
}
return circle;
}