Advertisement
avr39ripe

jsFunctionsBasics

Feb 4th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.30 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.     <script>
  9.         'use strict'
  10.  
  11.         function sayHi() {
  12.             alert("Hello, from JS function!");
  13.         }
  14.  
  15.         function addOne(val) {
  16.             alert(`Add ONE! - ${++val}`);
  17.         }
  18.  
  19.         function maxNumInt(numA, numB, interactive = true) {
  20.             if (interactive) {
  21.                 numA = +prompt("Enter numA");
  22.                 numB = +prompt("Enter numB");
  23.             }
  24.                 let result = (numA > numB) ? numA : numB;
  25.  
  26.             if (interactive) {
  27.                 alert(`max num is ${result}`);
  28.             }
  29.  
  30.             return result;
  31.         }
  32.  
  33.  
  34.         function max(numA, numB) {
  35.            return (numA > numB) ? numA : numB;
  36.         }
  37.  
  38.         function retTester(boundary, base) {
  39.             let sum = base;
  40.             for (let i = 0; i < 100; ++i) {
  41.                console.log(`inside loop - ${i}`);
  42.                sum += i;
  43.  
  44.                if (i == boundary) {
  45.                    console.log(`Boundary reached :(`);
  46.                    return;
  47.                }
  48.                if (sum > 30) {
  49.                     console.log(`Sum is TOOO BIG  :( - ${sum}`);
  50.                     return;
  51.                 }
  52.             }
  53.         }
  54.  
  55.  
  56.        // let A = +prompt("Enter A");
  57.        // let B = +prompt("Enter B");
  58.  
  59.        //console.log(maxNum(10, 38));
  60.  
  61.        
  62.  
  63.        // let res = maxNum(10, 38);
  64.  
  65.         //maxNumBAD();
  66.  
  67.         maxNumInt(0, 0 , false);
  68.         let res = maxNumInt(10, 38, false);
  69.         console.log(res);
  70.  
  71.         //retTester(12, -10000);
  72.  
  73.         //let res = maxNum(42, 245);
  74.  
  75.         //alert(`res is - ${res}`);
  76.  
  77.        
  78.  
  79.         //for (let i = 0; i < 5; ++i) {
  80.        //    sayHi();
  81.        //}
  82.  
  83.        
  84.        //addOne(+prompt("Enter value for addOne"));
  85.        //addOne();
  86.  
  87.        //
  88.  
  89.  
  90.  
  91.        //let num1 = +prompt("Enter first number");
  92.        //let sum1 = 0;
  93.  
  94.        //for (sum1 = 0; num1; sum1 += num1 % 10, num1 = Math.floor(num1 / 10));
  95.  
  96.        //// further work
  97.  
  98.        //let num2 = +prompt("Enter second number");
  99.        //let sum2 = 0;
  100.  
  101.        //for (sum2 = 0; num2; sum2 += num2 % 10, num2 = Math.floor(num2 / 10));
  102.  
  103.    </script>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement