Last active
November 13, 2018 20:44
-
-
Save lkraman/14ba01220d4d00df6583b43518f1046c to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/lkramanfirstmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Write a function called even that accepts a single number | |
as an argument and returns true if the number is even and | |
false if the number is odd.*/ | |
let even = function(n){ | |
if (n % 2 === 0){ | |
return true | |
} | |
else | |
{ | |
return false | |
} | |
}; | |
console.log(even(7)); | |
/*Write a function called squared that accepts a single | |
number as an argument and returns the perfect square of the number. | |
So squared(5) returns 25 and squared(3) returns 9.*/ | |
let squared = function(n){ | |
let exp = Math.pow(n, 2) | |
return exp; | |
} | |
console.log(squared(5)); | |
/*Write a function called food that accepts no arguments | |
and returns an array of your 3 favorite foods.*/ | |
function food() { | |
let food = ['pizza', 'bread', 'chicken'] | |
return food; | |
} | |
console.log(food()); | |
/*Write a function called menu that accepts no arguments and | |
returns an object of your 3 favorite foods with the name of | |
the foods as keys and the price of each item as the values.*/ | |
function menu(){ | |
let menuFoods = { | |
cake: 3, | |
chicken: 5, | |
egg: 1, | |
} | |
return menuFoods; | |
}; | |
console.log(menu()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/*Write a function called even that accepts a single number | |
as an argument and returns true if the number is even and | |
false if the number is odd.*/ | |
let even = function(n){ | |
if (n % 2 === 0){ | |
return true | |
} | |
else | |
{ | |
return false | |
} | |
}; | |
console.log(even(7)); | |
/*Write a function called squared that accepts a single | |
number as an argument and returns the perfect square of the number. | |
So squared(5) returns 25 and squared(3) returns 9.*/ | |
let squared = function(n){ | |
let exp = Math.pow(n, 2) | |
return exp; | |
} | |
console.log(squared(5)); | |
/*Write a function called food that accepts no arguments | |
and returns an array of your 3 favorite foods.*/ | |
function food() { | |
let food = ['pizza', 'bread', 'chicken'] | |
return food; | |
} | |
console.log(food()); | |
/*Write a function called menu that accepts no arguments and | |
returns an object of your 3 favorite foods with the name of | |
the foods as keys and the price of each item as the values.*/ | |
function menu(){ | |
let menuFoods = { | |
cake: 3, | |
chicken: 5, | |
egg: 1, | |
} | |
return menuFoods; | |
}; | |
console.log(menu()); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/*Write a function called even that accepts a single number | |
as an argument and returns true if the number is even and | |
false if the number is odd.*/ | |
let even = function(n){ | |
if (n % 2 === 0){ | |
return true | |
} | |
else | |
{ | |
return false | |
} | |
}; | |
console.log(even(7)); | |
/*Write a function called squared that accepts a single | |
number as an argument and returns the perfect square of the number. | |
So squared(5) returns 25 and squared(3) returns 9.*/ | |
let squared = function(n){ | |
let exp = Math.pow(n, 2) | |
return exp; | |
} | |
console.log(squared(5)); | |
/*Write a function called food that accepts no arguments | |
and returns an array of your 3 favorite foods.*/ | |
function food() { | |
let food = ['pizza', 'bread', 'chicken'] | |
return food; | |
} | |
console.log(food()); | |
/*Write a function called menu that accepts no arguments and | |
returns an object of your 3 favorite foods with the name of | |
the foods as keys and the price of each item as the values.*/ | |
function menu(){ | |
let menuFoods = { | |
cake: 3, | |
chicken: 5, | |
egg: 1, | |
} | |
return menuFoods; | |
}; | |
console.log(menu()); | |
</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment