Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 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. <h2>JavaScript String Properties</h2>
  10.  
  11. <p>The length property returns the length of a string:</p>
  12.  
  13. <p id="count"></p>
  14.  
  15. <script>
  16. var wordcount = "this is a senctence";
  17. document.getElementById("count").innerHTML = wordcount.length;
  18. </script>
  19. <h3> Sum Nested Arrays </h3>
  20. <p>Click the button to get the sum of the rounded numbers in the array.</p>
  21. <button onclick="sumNested()">Try it</button>
  22.  
  23. <p>Sum of numbers in array: <span id="sum"></span></p>
  24.  
  25. <script>
  26. var numbers = [15.5, 2.3, 1.1, [4.7]];
  27.  
  28. function getSum(total, num) {
  29. return total + Math.round(num);
  30. }
  31. function sumNested(item) {
  32. document.getElementById("sum").innerHTML = numbers.reduce(getSum, 0);
  33. }
  34. </script>
  35. <h3>Anagram Tester</h3>
  36. <script>
  37.  
  38. function areTheseAnagrams (str1, str2) {
  39.  
  40. if (str1.length !== str2.length) {
  41. return false;
  42. }
  43.  
  44. var sortStr1 = str1.split('').sort().join('');
  45. var sortStr2 = str2.split('').sort().join('');
  46.  
  47. return (sortStr1 === sortStr2);
  48. }
  49.  
  50. console.log(areTheseAnagrams('dog','god')); // true
  51. console.log(areTheseAnagrams('foo','bar')); // false
  52. console.log(areTheseAnagrams('foo','fooo')); // false
  53. </script>
  54. <h3> Property path Evaluation </h3>
  55. <script>
  56. const object1 = {
  57. a: 'somestring',
  58. b: 42,
  59. c: false
  60. };
  61.  
  62. console.log(Object.values(object1));
  63. // expected output: Array ["somestring", 42, false]
  64. </script>
  65. <h3> FizzBuzz</h3>
  66. <script>
  67. //Fizzbuzz problem in Javascript
  68.  
  69. //start the function
  70. function fizzbuzz(param){
  71. //create an array
  72. var array = [];
  73. //begin the loop
  74. for(i=1; i <= param; i++){
  75. array.push(i)
  76. //detect values divisble by 3 and 5
  77. if(i % 3 === 0 && i % 5 === 0){
  78. //push to the array
  79. array.push("fizzbuz"+i);
  80. }
  81. //detect values divisible by 3
  82. else if(i % 3 === 0){
  83. array.push("fizz"+i);
  84. }
  85. //detect values divisible by 5
  86. else if(i % 5 === 0){
  87. array.push("buzz"+i);
  88. }
  89. }
  90. //print array
  91. console.log(array);
  92. //variable to handle array summation
  93. var sum = array.reduce(function(a,b){return a + b;}, 0);
  94.  
  95. }
  96.  
  97. //call function
  98. fizzbuzz(15);
  99. </script>
  100. <h3>get speed</h3>
  101. <script>
  102. const car = new Set();
  103. car.add(42);
  104. car.add(0);
  105.  
  106. var speed = car.values();
  107.  
  108. console.log(speed.next().value);
  109. console.log(speed.next().value);
  110. </script>
  111.  
  112.  
  113.  
  114. </body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement