Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //In these first 6 questions, replace `null` with the answer
  2.  
  3. //create a string variable, it can contain anything
  4. const newString = 'null';
  5.  
  6. //create a number variable, it an be any number
  7. const newNum = 0;
  8.  
  9. //create a boolean variable
  10. const newBool = true;
  11.  
  12. //solve the following math problem
  13. const newSubtract = 10 - 5 === 5;
  14.  
  15. //Solve the following math problem
  16. const newMultiply = 10 * 4 === 40 ;
  17.  
  18. //Solve the following math problem:
  19. const newModulo = 21 % 5 === 1 ;
  20.  
  21.  
  22.  
  23. //In the next 22 problems you will compete the function. All of your code will go inside of the function braces.
  24. //Make sure you use return when the prompt asks you to.
  25. //hint: console.log() will NOT work.
  26. //Do not change any of the function names
  27.  
  28. function returnString(str) {
  29.   //simply return the string provided: str
  30.   return str;
  31. }
  32.  
  33. function add(x, y) {
  34.   // x and y are numbers
  35.   // add x and y together and return the value
  36.   // code here
  37.   return x + y;
  38. }
  39.  
  40. function subtract(x, y) {
  41.   // subtract y from x and return the value
  42.   // code here
  43.   return x - y;
  44. }
  45.  
  46. function multiply(x, y) {
  47.   // multiply x by y and return the value
  48.   // code here
  49.   return x * y;
  50. }
  51.  
  52. function divide(x, y) {
  53.   // divide x by y and return the value
  54.   // code here
  55.   return x / y;
  56. }
  57.  
  58. function areEqual(x, y) {
  59.   // return true if x and y are the same
  60.   // otherwise return false
  61.   // code here
  62.   if(x === y) {
  63.     return true;
  64.   }
  65. }
  66.  
  67. function areSameLength(str1, str2) {
  68.   // return true if the two strings have the same length
  69.   // otherwise return false
  70.   // code here
  71.   if(str.length === str2.length) {
  72.     return true
  73.   }
  74. }
  75.  
  76. function lessThanNinety(num) {
  77.   // return true if the function argument: num , is less than ninety
  78.   // otherwise return false
  79.   // code here
  80.   if (num < 90) {
  81.     return true;
  82.   }
  83.   return false;
  84. }
  85.  
  86. function greaterThanFifty(num) {
  87.   // return true if num is greater than fifty
  88.   // otherwise return false
  89.   // code here
  90.   if(num > 50) {
  91.     return true;
  92.   }
  93.   return false;
  94. }
  95.  
  96. function getRemainder(x, y) {
  97.   // return the remainder from dividing x by y
  98.   // code here
  99.   return x % y;
  100. }
  101.  
  102. function isEven(num) {
  103.   // return true if num is even
  104.   // otherwise return false
  105.   // code here
  106.   if(num%2===0) {
  107.     return true;
  108.   }
  109.   return false;
  110. }
  111.  
  112. function isOdd(num) {
  113.   // return true if num is odd
  114.   // otherwise return false
  115.   // code here
  116.   if(num%2 > 0) {
  117.     return true;
  118.   }
  119.   return false;
  120. }
  121.  
  122. function square(num) {
  123.   // square num and return the new value
  124.   // hint: NOT square root!
  125.   // code here
  126.   return Math.pow(num,2);
  127. }
  128.  
  129. function cube(num) {
  130.   // cube num and return the new value
  131.   // code here
  132.   return Math.pow(num,3);
  133. }
  134.  
  135. function raiseToPower(num, exponent) {
  136.   // raise num to whatever power is passed in as exponent
  137.   // code here
  138.   return Math.pow(num, exponent);
  139. }
  140.  
  141. function roundNumber(num) {
  142.   // round num and return it
  143.   // code here
  144.   return Math.round(num);
  145. }
  146.  
  147. function roundUp(num) {
  148.   // round num up and return it
  149.   // code here
  150. }
  151.  
  152. function addExclamationPoint(str) {
  153.   // add an exclamation point to the end of str and return the new string
  154.   // 'hello world' -> 'hello world!'
  155.   // code here
  156.   const newstr = str + '!';
  157.   return newstr;
  158. }
  159.  
  160. function combineNames(firstName, lastName) {
  161.   // return firstName and lastName combined as one string and separated by a space.
  162.   // 'Lambda', 'School' -> 'Lambda School'
  163.   // code here
  164.   const name = firstName + lastName;
  165.   return name;
  166. }
  167.  
  168. function getGreeting(name) {
  169.   // Take the name string and concatenate other strings onto it so it takes the following form:
  170.   // 'Sam' -> 'Hello Sam!'
  171.   // code here
  172.   const newstr = 'Hello' + name + '!';
  173.   return newstr;
  174. }
  175.  
  176. // The next three questions will have you implement math area formulas.
  177. // If you can't remember these area formulas then head over to Google.
  178.  
  179. function getRectangleArea(length, width) {
  180.   // return the area of the rectangle by using length and width
  181.   // code here
  182.   return length * width;
  183. }
  184.  
  185. function getTriangleArea(base, height) {
  186.   // return the area of the triangle by using base and height
  187.   // code here
  188.   return 0.5 * base * height;
  189. }
  190.  
  191. // Do not modify code below this line.
  192. // --------------------------------
  193.  
  194. module.exports = {
  195.   newString,
  196.   newNum,
  197.   newBool,
  198.   newSubtract,
  199.   newMultiply,
  200.   newModulo,
  201.   returnString,
  202.   areSameLength,
  203.   areEqual,
  204.   lessThanNinety,
  205.   greaterThanFifty,
  206.   add,
  207.   subtract,
  208.   divide,
  209.   multiply,
  210.   getRemainder,
  211.   isEven,
  212.   isOdd,
  213.   square,
  214.   cube,
  215.   raiseToPower,
  216.   roundNumber,
  217.   roundUp,
  218.   addExclamationPoint,
  219.   combineNames,
  220.   getGreeting,
  221.   getRectangleArea,
  222.   getTriangleArea,
  223. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement