Guest User

Untitled

a guest
Jan 21st, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. //-----------------------------------------
  12. //Name: <Nick Kopjas>
  13. //-----------------------------------------
  14.  
  15.  
  16. //-----------------------------------------
  17. // Exercise: <Property Path Evaluation>
  18. //-----------------------------------------
  19.  
  20. var property;
  21. var obj = {"a":"1",
  22. "b":{
  23. "c":"2",
  24. "d":"3"
  25. }
  26. };
  27.  
  28. var valueAt = function propertyValueAt (obj, property){
  29. console.log(obj[property])
  30.  
  31. };
  32.  
  33. valueAt(obj, "b");
  34.  
  35. //-----------------------------------------
  36. //Name: <Nick Kopjas>
  37. //-----------------------------------------
  38.  
  39.  
  40. //-----------------------------------------
  41. // Exercise: <Sum Nested Arrays>
  42. //-----------------------------------------
  43.  
  44. function sumNested(array){
  45. var sum = 0;
  46. for (var i = 0; i < array.length; i++) {
  47. if (typeof array[i] == 'object')
  48. sum += sumNested(array[i]);
  49. else
  50. sum += array[i];
  51. }
  52. return sum;
  53. }
  54.  
  55. console.log(sumNested([2, [4, 6], 5]))
  56.  
  57. //-----------------------------------------
  58. //Name: <Nick Kopjas>
  59. //-----------------------------------------
  60.  
  61.  
  62. //-----------------------------------------
  63. // Exercise: <Word Count>
  64. //-----------------------------------------
  65.  
  66. function wordCount(sentence){
  67. var count=0;
  68. for (var i=0; i<sentence.length; i++){
  69. if (sentence.charAt(i) == " ") {
  70. count++;
  71. }
  72. }
  73. return count + 1;
  74. }
  75.  
  76. console.log(wordCount("This is a sentence"));
  77.  
  78. //-----------------------------------------
  79. //Name: <Nick Kopjas>
  80. //-----------------------------------------
  81.  
  82.  
  83. //-----------------------------------------
  84. // Exercise: <Anagram Tester>
  85. //-----------------------------------------
  86.  
  87. function areTheseAnagrams(a1, a2){
  88. var lowercaseA1 = a1.toLowerCase();
  89. var lowercaseA2 = a2.toLowerCase();
  90.  
  91. if (lowercaseA1 === lowercaseA2){
  92. return false;
  93. }
  94.  
  95. var sortedA1 = lowercaseA1.split('').sort().join('');
  96. var sortedA2 = lowercaseA2.split('').sort().join('');
  97.  
  98. return sortedA1 === sortedA2;
  99. }
  100.  
  101. console.log(areTheseAnagrams("abc", "cba"));
  102.  
  103. //-----------------------------------------
  104. //Name: <Nick Kopjas>
  105. //-----------------------------------------
  106.  
  107.  
  108. //-----------------------------------------
  109. // Exercise: <Analyze Prices>
  110. //-----------------------------------------
  111.  
  112. var prices = [1,2,3,4,5,6,7,8];
  113. function analyzePrice(prices){
  114. var buyIndex = 0;
  115. var sellIndex = 0;
  116.  
  117. var low = prices.sort(function(a, b){return a-b});
  118. var high = prices.sort(function(a, b){return b-a});
  119. return "{buy index : " + low + ", sell index : " + high + "}";
  120.  
  121. }
  122. console.log(analyzePrice(prices));
  123.  
  124. //-----------------------------------------
  125. //Name: <Nick Kopjas>
  126. //-----------------------------------------
  127.  
  128.  
  129. //-----------------------------------------
  130. // Exercise: <Fizz Buzz>
  131. //-----------------------------------------
  132.  
  133. function fizzBuzz(n){
  134.  
  135. for (var i=0; i<n.length; i++){
  136. if (n % 3 === 0 && n % 5 ===0){
  137. console.log("FizzBuzz");
  138. }
  139. else if (n % 3 === 0){
  140. console.log("Fizz");
  141. }
  142. else if (n % 5 === 0){
  143. console.log("Buzz");
  144. }else{
  145. console.log(n);
  146. }
  147.  
  148. }
  149. }
  150. console.log(fizzBuzz(15));
  151. console.log(fizzBuzz(5));
  152. console.log(fizzBuzz(30));
  153.  
  154. //-----------------------------------------
  155. //Name: <Nick Kopjas>
  156. //-----------------------------------------
  157.  
  158.  
  159. //-----------------------------------------
  160. // Exercise: <Object Oriented Programming - Car>
  161. //-----------------------------------------
  162.  
  163. var car = new Car();
  164.  
  165. console.log(car.getSpeed());
  166. car.setSpeed(10);
  167. console.log(car.setSpeed());
  168. car.stop();
  169. console.log(car.getSpeed());
  170. </script>
  171.  
  172.  
  173.  
  174. <script id="jsbin-source-javascript" type="text/javascript">//-----------------------------------------
  175. //Name: <Nick Kopjas>
  176. //-----------------------------------------
  177.  
  178.  
  179. //-----------------------------------------
  180. // Exercise: <Property Path Evaluation>
  181. //-----------------------------------------
  182.  
  183. var property;
  184. var obj = {"a":"1",
  185. "b":{
  186. "c":"2",
  187. "d":"3"
  188. }
  189. };
  190.  
  191. var valueAt = function propertyValueAt (obj, property){
  192. console.log(obj[property])
  193.  
  194. };
  195.  
  196. valueAt(obj, "b");
  197.  
  198. //-----------------------------------------
  199. //Name: <Nick Kopjas>
  200. //-----------------------------------------
  201.  
  202.  
  203. //-----------------------------------------
  204. // Exercise: <Sum Nested Arrays>
  205. //-----------------------------------------
  206.  
  207. function sumNested(array){
  208. var sum = 0;
  209. for (var i = 0; i < array.length; i++) {
  210. if (typeof array[i] == 'object')
  211. sum += sumNested(array[i]);
  212. else
  213. sum += array[i];
  214. }
  215. return sum;
  216. }
  217.  
  218. console.log(sumNested([2, [4, 6], 5]))
  219.  
  220. //-----------------------------------------
  221. //Name: <Nick Kopjas>
  222. //-----------------------------------------
  223.  
  224.  
  225. //-----------------------------------------
  226. // Exercise: <Word Count>
  227. //-----------------------------------------
  228.  
  229. function wordCount(sentence){
  230. var count=0;
  231. for (var i=0; i<sentence.length; i++){
  232. if (sentence.charAt(i) == " ") {
  233. count++;
  234. }
  235. }
  236. return count + 1;
  237. }
  238.  
  239. console.log(wordCount("This is a sentence"));
  240.  
  241. //-----------------------------------------
  242. //Name: <Nick Kopjas>
  243. //-----------------------------------------
  244.  
  245.  
  246. //-----------------------------------------
  247. // Exercise: <Anagram Tester>
  248. //-----------------------------------------
  249.  
  250. function areTheseAnagrams(a1, a2){
  251. var lowercaseA1 = a1.toLowerCase();
  252. var lowercaseA2 = a2.toLowerCase();
  253.  
  254. if (lowercaseA1 === lowercaseA2){
  255. return false;
  256. }
  257.  
  258. var sortedA1 = lowercaseA1.split('').sort().join('');
  259. var sortedA2 = lowercaseA2.split('').sort().join('');
  260.  
  261. return sortedA1 === sortedA2;
  262. }
  263.  
  264. console.log(areTheseAnagrams("abc", "cba"));
  265.  
  266. //-----------------------------------------
  267. //Name: <Nick Kopjas>
  268. //-----------------------------------------
  269.  
  270.  
  271. //-----------------------------------------
  272. // Exercise: <Analyze Prices>
  273. //-----------------------------------------
  274.  
  275. var prices = [1,2,3,4,5,6,7,8];
  276. function analyzePrice(prices){
  277. var buyIndex = 0;
  278. var sellIndex = 0;
  279.  
  280. var low = prices.sort(function(a, b){return a-b});
  281. var high = prices.sort(function(a, b){return b-a});
  282. return "{buy index : " + low + ", sell index : " + high + "}";
  283.  
  284. }
  285. console.log(analyzePrice(prices));
  286.  
  287. //-----------------------------------------
  288. //Name: <Nick Kopjas>
  289. //-----------------------------------------
  290.  
  291.  
  292. //-----------------------------------------
  293. // Exercise: <Fizz Buzz>
  294. //-----------------------------------------
  295.  
  296. function fizzBuzz(n){
  297.  
  298. for (var i=0; i<n.length; i++){
  299. if (n % 3 === 0 && n % 5 ===0){
  300. console.log("FizzBuzz");
  301. }
  302. else if (n % 3 === 0){
  303. console.log("Fizz");
  304. }
  305. else if (n % 5 === 0){
  306. console.log("Buzz");
  307. }else{
  308. console.log(n);
  309. }
  310.  
  311. }
  312. }
  313. console.log(fizzBuzz(15));
  314. console.log(fizzBuzz(5));
  315. console.log(fizzBuzz(30));
  316.  
  317. //-----------------------------------------
  318. //Name: <Nick Kopjas>
  319. //-----------------------------------------
  320.  
  321.  
  322. //-----------------------------------------
  323. // Exercise: <Object Oriented Programming - Car>
  324. //-----------------------------------------
  325.  
  326. var car = new Car();
  327.  
  328. console.log(car.getSpeed());
  329. car.setSpeed(10);
  330. console.log(car.setSpeed());
  331. car.stop();
  332. console.log(car.getSpeed());
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339. </script></body>
  340. </html>
Add Comment
Please, Sign In to add comment