|
| 1 | +// LAB SCR |
| 2 | +function run_lab() { |
| 3 | + // OUPUT VAR |
| 4 | + let output_var = []; |
| 5 | + |
| 6 | + function cl(str) { |
| 7 | + if (str == null) { |
| 8 | + str = ""; |
| 9 | + } |
| 10 | + output_var.push(str); |
| 11 | + console.log(str); |
| 12 | + } |
| 13 | + |
| 14 | + // 1. Declare and Use Variables |
| 15 | + let studentName = "Carmack Romero"; |
| 16 | + let studentAge = 92; |
| 17 | + let isEnrolled = false; |
| 18 | + cl(); |
| 19 | + |
| 20 | + // LOG TO CONSOLE |
| 21 | + cl(`STUDENT NAME[${studentName}]`); |
| 22 | + cl(`STUDENT AGE[${studentAge}]`); |
| 23 | + cl("IS ENROLLED[" + isEnrolled + "]"); |
| 24 | + cl(); |
| 25 | + |
| 26 | + // 2. Demonstrate Data Types |
| 27 | + |
| 28 | + // Create and log examples for all five basic JavaScript data types: |
| 29 | + // String: A text value. |
| 30 | + // Number: An integer or floating-point number. |
| 31 | + // Boolean: true or false. |
| 32 | + // Array: A collection of values (e.g., ["apple", "banana", "cherry"]). |
| 33 | + // Object: An entity with properties (e.g., { firstName: "John", lastName: "Doe" }). |
| 34 | + |
| 35 | + let strVar = "I'm a string of characters!"; |
| 36 | + let numVar = -999; |
| 37 | + let booleanVar = false; |
| 38 | + let arrayVar = ["This", "sure", "is", "a", "cool", "array", "!"]; |
| 39 | + let objVar = { |
| 40 | + whatAmI: "an object", |
| 41 | + isCool: true, |
| 42 | + }; |
| 43 | + |
| 44 | + // LOG TO CONSOLE |
| 45 | + cl("WHAT IS THIS strVar? [" + strVar + "]"); |
| 46 | + cl("IS THIS numVar[" + numVar + "] BIGGER THAN ZERO?(" + (numVar > 0) + ")"); |
| 47 | + cl( |
| 48 | + "IS THIS boolVar[" + booleanVar + "] FALSE?(" + (booleanVar == false) + ")" |
| 49 | + ); |
| 50 | + |
| 51 | + cl( |
| 52 | + "WHAT IS THIS arrayVar[" + |
| 53 | + arrayVar + |
| 54 | + '] AS A STRING? "' + |
| 55 | + arrayVar.join(" ") + |
| 56 | + '")' |
| 57 | + ); |
| 58 | + cl(); |
| 59 | + |
| 60 | + cl("THIS OBJECT[" + objVar + "]..."); |
| 61 | + cl("WHAT IS THIS OBJECT[" + objVar.whatAmI + "]"); |
| 62 | + cl("IS THIS OBJECT COOL?[" + objVar.isCool + "]"); |
| 63 | + cl(); |
| 64 | + |
| 65 | + // 3. Use Basic Operators |
| 66 | + // Perform and log operations using different types of operators: |
| 67 | + |
| 68 | + // Arithmetic Operators: Addition (+), Subtraction (-), Multiplication (*), and Division (/). |
| 69 | + |
| 70 | + let opValA = 1000.0; |
| 71 | + let opValB = -250 + Math.random() * 500; |
| 72 | + opValB = Math.round(opValB); |
| 73 | + |
| 74 | + cl("The value of opValA is [" + opValA + "]"); |
| 75 | + cl("The value of opValB is [" + opValB + "]"); |
| 76 | + |
| 77 | + let opValSum = opValA + opValB; |
| 78 | + let opValSub = opValA - opValB; |
| 79 | + let opValMul = opValA * opValB; |
| 80 | + let opValDiv = opValA / opValB; |
| 81 | + |
| 82 | + cl("(" + opValA + " + " + opValB + " = " + opValSum + ")"); |
| 83 | + cl("(" + opValA + " - " + opValB + " = " + opValSub + ")"); |
| 84 | + cl("(" + opValA + " * " + opValB + " = " + opValMul + ")"); |
| 85 | + cl("(" + opValA + " / " + opValB + " = " + Math.round(opValDiv) + ") * ROUNDED"); |
| 86 | + cl(); |
| 87 | + |
| 88 | + // Comparison Operators: Greater than (>), Less than (<), Equal to (===), and Not equal (!==). |
| 89 | + cl("(" + opValA + " > " + opValB + " is " + (opValA > opValB) + ")"); |
| 90 | + cl("(" + opValA + " < " + opValB + " is " + (opValA < opValB) + ")"); |
| 91 | + cl("(" + opValA + " === " + opValB + " is " + (opValA === opValB) + ")"); |
| 92 | + cl("(" + opValA + " !== " + opValB + " is " + (opValA !== opValB) + ")"); |
| 93 | + cl(); |
| 94 | + |
| 95 | + // Logical Operators: AND (&&), OR (||), and NOT (!). |
| 96 | + |
| 97 | + let opValC = -1000 + Math.random() * 2000; |
| 98 | + opValC = Math.round(opValC * 10) / 10; |
| 99 | + cl("The value of opValC is [" + opValC + "]"); |
| 100 | + |
| 101 | + if (opValA > 0.0 && opValC > 0.0) { |
| 102 | + cl( |
| 103 | + "BOTH A[" + opValA + "] and C[" + opValC + "] VALUES ARE MORE THAN ZERO" |
| 104 | + ); |
| 105 | + } else { |
| 106 | + cl("EITHER A[" + opValA + "] or C[" + opValC + "] ISN'T MORE THAN ZERO"); |
| 107 | + } |
| 108 | + |
| 109 | + if (opValA > 0.0 || opValC > 0.0) { |
| 110 | + cl("EITHER A[" + opValA + "] and C[" + opValC + "] IS MORE THAN ZERO"); |
| 111 | + } else { |
| 112 | + cl("NEITHER A[" + opValA + "] or C[" + opValC + "] IS MORE THAN ZERO"); |
| 113 | + } |
| 114 | + cl(); |
| 115 | + |
| 116 | + let opValD = Math.random() > 0.5; |
| 117 | + |
| 118 | + cl("The value of opValD is [" + opValD + "]"); |
| 119 | + cl("The value of !opValD is [" + !opValD + "]"); |
| 120 | + cl(); |
| 121 | + |
| 122 | + // RETURN OUTPUT VAR TO PAGE |
| 123 | + console.log("OUTPUT VAR LENGTH(" + output_var.length + ")"); |
| 124 | + |
| 125 | + let ret_str = output_var.join("\n"); |
| 126 | + |
| 127 | + return ret_str; |
| 128 | +} |
| 129 | + |
| 130 | +// QUICK & EASY MAKE AVAIL TO THE INDEX.HTML |
| 131 | +window.run_lab = run_lab; |
0 commit comments