Advertisement
avr39ripe

jsFunctionExprArrowFuncAdv

Feb 11th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <h1 id="mesg"></h1>;
  9.  
  10.     <script>
  11.         'use strict'
  12.         //function breakNumber(num, selector = 1) {
  13.            
  14.         //    for (let digit; digit = num% 10, num; num = Math.floor(num / 10)) {
  15.         //        if (selector == 1) {
  16.         //            console.log(digit);
  17.         //        }
  18.         //        else if (selector == 2) {
  19.         //            alert(digit);
  20.         //        }
  21.         //        else if (selector == 3) {
  22.         //            msg.innerHTML += `${digit} `;
  23.         //        }
  24.                                
  25.         //    }
  26.         //}
  27.  
  28.         function breakNumber(num, printer, parity) {
  29.             for (let digit; digit = num % 10, num; num = Math.floor(num / 10)) {
  30.                 if (parity(digit)) {
  31.                     printer(digit);
  32.                 }
  33.             }
  34.         }
  35.  
  36.         function mainFunc() {
  37.  
  38.             let alertPrint = function (msg) {
  39.                 alert(msg);
  40.             };
  41.  
  42.             let consolePrint = function (msg) {
  43.                 console.log(msg);
  44.             };
  45.  
  46.             let htmlPrint = function (msg) {
  47.                 mesg.innerHTML += `${msg} `;
  48.             };
  49.  
  50.             let odd = function (dig) { return (dig % 2) != 0; };
  51.             let even = function (dig) { return (dig % 2) == 0; };
  52.             let greaterFive = function (dig) { return dig > 5; };
  53.  
  54.  
  55.             let num = 12345627819;
  56.  
  57.             //breakNumber(num, htmlPrint, greaterFive);
  58.             breakNumber(12345627819, htmlPrint, (dig) => true );
  59.             //breakNumber(8472364, htmlPrint, odd);
  60.         }
  61.  
  62.         mainFunc();
  63.        
  64.         //function printMsg(msg) {
  65.         //    console.log(msg);
  66.         //}
  67.  
  68.         //function max(a, b) {
  69.         //    return a > b ? a : b;
  70.         //}
  71.  
  72.         //let printer = function (msg) {
  73.         //    console.log(msg);
  74.         //};
  75.  
  76.  
  77.  
  78.         //printMsg('Hello, from JS code :)')
  79.  
  80.         //printer('Another way to make function in JS :)');
  81.  
  82.         //let res;
  83.         //res = max(2, 5);
  84.  
  85.         //msg.innerHTML = 'Test h1 content from JS!';
  86.         //console.log(`Content of h1 with id="msg" is ${msg.innerHTML}`);
  87.        
  88.  
  89.     </script>
  90. </body>
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement