Guest User

Untitled

a guest
Dec 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. function lesserNum(num1, num2) {
  2. if(num1 === num2) return num1;
  3. if(num1 < num2) return num1;
  4. if(num2 < num1) return num2;
  5. }
  6.  
  7. // lesserNum(19, 4); //4
  8.  
  9. // Write a function isHotdogASandwich which returns true by default, but if given any input whatsoever, returns "Alright, MAYBE. Who's to say?".
  10.  
  11. function isHotdogASandwich(input) {
  12. if(input === undefined) return true;
  13. return ("Alright, MAYBE. Who's to say?")
  14. }
  15.  
  16. // isHotdogASandwich(); //true
  17.  
  18. // Write a function billTotal which takes in a number, and returns the total with a 9.875% tax as well as 20% tip calculated.
  19.  
  20. function billTotal(subTotal) {
  21. var tax = subTotal * .09875;
  22. var tip = subTotal * .2;
  23. return tax + tip + subTotal;
  24. }
  25.  
  26. // billTotal(120); //155.85
  27.  
  28. // Write a function budgetStatus which takes in a number, and returns a string stating the status of your budget. If the input is greater than 250, the output should be an "over budget" message along with the amount (see below). If the input is less than or equal to 250, the output should be an "Under budget" message along with the amount (again, see below).
  29.  
  30. function budgetStatus(cost) {
  31. if(cost <= 250) {
  32. var under = 250 - cost;
  33. return 'Under budget by ' + under + ' dollar(s)';
  34. } else {
  35. var over = cost - 250;
  36. return 'Over budget by ' + over + ' dollar(s)'
  37. }
  38. }
  39.  
  40. var day1Expenditures = 155;
  41. var day2Expenditures = 411;
  42. var day3Expenditures = 249;
  43.  
  44. // budgetStatus(day1Expenditures); //Under budget by 95 dollar(s)
  45.  
  46. // Write a function secondsConverter which takes in a number and returns a string denoting how many minutes and seconds it converts to. Note: If it is greater than 60 minutes, do not worry about converting it to hours.
  47.  
  48.  
  49. // input - seconds
  50. // output - seconds converted to minutes and the remainder is seconds;
  51.  
  52. function secondsConverter(seconds) {
  53. var resultSeconds = seconds % 60;
  54. var minutes = seconds / 60;
  55. return (Math.floor(minutes) + ' minutes and ' + resultSeconds + ' seconds')
  56. }
  57.  
  58. // secondsConverter(300); //"5 minutes and 0 seconds"
  59.  
  60. // Write a function arrayInfo which accepts an array and returns a string with the following information: the length of the array, the last index value of the array in a properly formatted string. You can assume the input array will always have at least 1 element.
  61.  
  62. function arrayInfo(arr){
  63. var length = arr.length;
  64. var lastElementIndex = arr.length - 1;
  65. return('Length: ' + length + ', index of last element: ' + lastElementIndex)
  66. }
  67.  
  68. // arrayInfo(["apple", "banana", "cranberry"]); //"Length: 3, index of last element: 2"
  69.  
  70. // Write a function acronymMaker which takes in an array of strings wordBank. Your function will return a string combining each of the wordBank's elements' first letters.
  71.  
  72. function acronymMaker(wordBank) {
  73. var result = ''
  74. wordBank.forEach(function(word) {
  75. result += word[0]
  76. });
  77. return result;
  78. }
  79.  
  80. // acronymMaker(["National", "Aeronautics", "Space", "Administration"]); //"NASA"
  81.  
  82. // Write a function getCurrentLocation which accepts an object, and returns the person's current city and state
  83.  
  84. function getCurrentLocation(person) {
  85. return person.city + ', ' + person.state;
  86. }
  87. // You can assume that your input argument will have always have a structure like this:
  88.  
  89. var personA = {
  90. name: "Lana Bartlett",
  91. age: 48,
  92. work: {
  93. title: "Product Manager",
  94. tenure: "3 years"
  95. },
  96. city: "Seattle",
  97. state: "Washington"
  98. }
  99.  
  100. // getCurrentLocation(personA); //"Seattle, Washington"
  101.  
  102. var personB = {
  103. name: "Sam Malone",
  104. age: 35,
  105. work: {
  106. title: "Owner/Bartender",
  107. tenure: "11 years"
  108. },
  109. city: "Boston",
  110. state: "Massachusetts"
  111. }
  112. // Passing in personB should result in:
  113.  
  114. // getCurrentLocation(personB); //"Boston, Massachusetts";
  115.  
  116. // Write a function multiplyBy which takes in two arguments: numberArray and factor, and returns a new array with each of the elements from the numberArray mutiplied by factor. Your function should not replace the values of the original array.
  117.  
  118. function multiplyBy(numberArray, factor) {
  119. return map(numberArray, function(number) {
  120. return number * factor;
  121. });
  122. }
  123.  
  124. // multiplyBy([0, 4, 8, 12], 3); //[0, 12, 24, 36]
  125.  
  126. // Write a function iValidatedThis which accepts an object, and adds two key-value pairs to that object -- dataChecked with the boolean value true, and checkedBy with your name (string).
  127.  
  128. function iValidatedThis(objectToCheck) {
  129. objectToCheck.dataChecked = true;
  130. objectToCheck.checkedBy = 'Heather'
  131. }
  132. // Calling your function should result in:
  133.  
  134. var carData = {make: "Toyota", model: "Prius", year: 2015, color: "Powder Blue"};
  135.  
  136. // iValidatedThis(carData);
  137.  
  138. // console.log(carData); //{make: "Toyota", model: "Prius", year: 2015, color: "Powder Blue", dataChecked: true, checkedBy: "Hack Reactor"};
  139.  
  140. // Write a function countInstancesOf which takes in a letter (string) and a sentence (string), and returns the number of occurences of that letter
  141.  
  142. function countInstancesOf(letter, sentence) {
  143. var acc = 0;
  144. for(var i = 0; i < sentence.length; i++) {
  145. if(sentence[i] === letter) {
  146. acc++
  147. }
  148. }
  149. return acc;
  150. }
Add Comment
Please, Sign In to add comment