Guest User

Untitled

a guest
Nov 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /*Write a function called even that accepts a single number
  2. as an argument and returns true if the number is even and
  3. false if the number is odd.*/
  4. let even = function(n){
  5. if (n % 2 === 0){
  6. return true
  7. }
  8. else
  9. {
  10. return false
  11. }
  12. };
  13.  
  14. console.log(even(7));
  15.  
  16. /*Write a function called squared that accepts a single
  17. number as an argument and returns the perfect square of the number.
  18. So squared(5) returns 25 and squared(3) returns 9.*/
  19.  
  20. let squared = function(n){
  21.  
  22. let exp = Math.pow(n, 2)
  23. return exp;
  24. }
  25.  
  26. console.log(squared(5));
  27.  
  28. /*Write a function called food that accepts no arguments
  29. and returns an array of your 3 favorite foods.*/
  30.  
  31. function food() {
  32. let food = ['pizza', 'bread', 'chicken']
  33. return food;
  34. }
  35. console.log(food());
  36.  
  37. /*Write a function called menu that accepts no arguments and
  38. returns an object of your 3 favorite foods with the name of
  39. the foods as keys and the price of each item as the values.*/
  40.  
  41. function menu(){
  42. let menuFoods = {
  43. cake: 3,
  44. chicken: 5,
  45. egg: 1,
  46. }
  47. return menuFoods;
  48. };
  49.  
  50. console.log(menu());
Add Comment
Please, Sign In to add comment