Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Study</title>
- </head>
- <body>
- <h1 id="mesg"></h1>;
- <script>
- 'use strict'
- //function breakNumber(num, selector = 1) {
- // for (let digit; digit = num% 10, num; num = Math.floor(num / 10)) {
- // if (selector == 1) {
- // console.log(digit);
- // }
- // else if (selector == 2) {
- // alert(digit);
- // }
- // else if (selector == 3) {
- // msg.innerHTML += `${digit} `;
- // }
- // }
- //}
- function breakNumber(num, printer, parity) {
- for (let digit; digit = num % 10, num; num = Math.floor(num / 10)) {
- if (parity(digit)) {
- printer(digit);
- }
- }
- }
- function mainFunc() {
- let alertPrint = function (msg) {
- alert(msg);
- };
- let consolePrint = function (msg) {
- console.log(msg);
- };
- let htmlPrint = function (msg) {
- mesg.innerHTML += `${msg} `;
- };
- let odd = function (dig) { return (dig % 2) != 0; };
- let even = function (dig) { return (dig % 2) == 0; };
- let greaterFive = function (dig) { return dig > 5; };
- let num = 12345627819;
- //breakNumber(num, htmlPrint, greaterFive);
- breakNumber(12345627819, htmlPrint, (dig) => true );
- //breakNumber(8472364, htmlPrint, odd);
- }
- mainFunc();
- //function printMsg(msg) {
- // console.log(msg);
- //}
- //function max(a, b) {
- // return a > b ? a : b;
- //}
- //let printer = function (msg) {
- // console.log(msg);
- //};
- //printMsg('Hello, from JS code :)')
- //printer('Another way to make function in JS :)');
- //let res;
- //res = max(2, 5);
- //msg.innerHTML = 'Test h1 content from JS!';
- //console.log(`Content of h1 with id="msg" is ${msg.innerHTML}`);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement