Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <h2>JavaScript String Properties</h2>
- <p>The length property returns the length of a string:</p>
- <p id="count"></p>
- <script>
- var wordcount = "this is a senctence";
- document.getElementById("count").innerHTML = wordcount.length;
- </script>
- <h3> Sum Nested Arrays </h3>
- <p>Click the button to get the sum of the rounded numbers in the array.</p>
- <button onclick="sumNested()">Try it</button>
- <p>Sum of numbers in array: <span id="sum"></span></p>
- <script>
- var numbers = [15.5, 2.3, 1.1, [4.7]];
- function getSum(total, num) {
- return total + Math.round(num);
- }
- function sumNested(item) {
- document.getElementById("sum").innerHTML = numbers.reduce(getSum, 0);
- }
- </script>
- <h3>Anagram Tester</h3>
- <script>
- function areTheseAnagrams (str1, str2) {
- if (str1.length !== str2.length) {
- return false;
- }
- var sortStr1 = str1.split('').sort().join('');
- var sortStr2 = str2.split('').sort().join('');
- return (sortStr1 === sortStr2);
- }
- console.log(areTheseAnagrams('dog','god')); // true
- console.log(areTheseAnagrams('foo','bar')); // false
- console.log(areTheseAnagrams('foo','fooo')); // false
- </script>
- <h3> Property path Evaluation </h3>
- <script>
- const object1 = {
- a: 'somestring',
- b: 42,
- c: false
- };
- console.log(Object.values(object1));
- // expected output: Array ["somestring", 42, false]
- </script>
- <h3> FizzBuzz</h3>
- <script>
- //Fizzbuzz problem in Javascript
- //start the function
- function fizzbuzz(param){
- //create an array
- var array = [];
- //begin the loop
- for(i=1; i <= param; i++){
- array.push(i)
- //detect values divisble by 3 and 5
- if(i % 3 === 0 && i % 5 === 0){
- //push to the array
- array.push("fizzbuz"+i);
- }
- //detect values divisible by 3
- else if(i % 3 === 0){
- array.push("fizz"+i);
- }
- //detect values divisible by 5
- else if(i % 5 === 0){
- array.push("buzz"+i);
- }
- }
- //print array
- console.log(array);
- //variable to handle array summation
- var sum = array.reduce(function(a,b){return a + b;}, 0);
- }
- //call function
- fizzbuzz(15);
- </script>
- <h3>get speed</h3>
- <script>
- const car = new Set();
- car.add(42);
- car.add(0);
- var speed = car.values();
- console.log(speed.next().value);
- console.log(speed.next().value);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement