Skip to content

Commit 3399049

Browse files
authored
Merge pull request mouredev#5991 from Sac-Corts/main
#00, #1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20, #21, #22, #23, #24, #25, #26, #27, #28, #29, mouredev#30 - JavaScript
2 parents 699a33a + bca803b commit 3399049

File tree

31 files changed

+2713
-0
lines changed

31 files changed

+2713
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// JavaScript programming language official website URL:
2+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript
3+
4+
// Single line comment in JavaScript
5+
6+
/*
7+
Multi-line comment in JavaScript
8+
It is used to describe longer blocks of code.
9+
or provide detailed information.
10+
*/
11+
12+
var myGlobalVariable = "This is a global variable"
13+
14+
let myLocalVariable = "This is a local variable";
15+
16+
const MY_CONSTANT = "This is a constant";
17+
18+
// String
19+
let textString = "Hello, I am a string";
20+
console.log(typeof(textString))
21+
22+
// Number
23+
let integer = 42;
24+
console.log(typeof(integer))
25+
26+
let float = 3.14;
27+
console.log(typeof(float))
28+
29+
// Boolean
30+
let boolean = true;
31+
console.log(typeof(boolean))
32+
33+
// Undefined
34+
let undefinedVar;
35+
console.log(typeof(undefinedVar))
36+
37+
// Null
38+
let nullVar = null;
39+
console.log(typeof(nullVar))
40+
41+
// Symbol
42+
let symbol = Symbol('description');
43+
console.log(typeof(symbol))
44+
45+
// BigInt
46+
let bigInt = BigInt(1234567890123456789012345678901234567890n);
47+
console.log(typeof(bigInt))
48+
49+
// Print the required text via terminal
50+
console.log("¡Hello, JavaScript!");
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Exercise //
2+
3+
// Arithmetic Operators
4+
let addition = 5 + 3;
5+
console.log("Addition: 5 + 3 = ", addition);
6+
7+
let subtraction = 10 - 5;
8+
console.log("Subtraction: 10 - 5 = ", subtraction);
9+
10+
let multiplication = 10 * 5;
11+
console.log("Multiplication: 10 * 5 = ", multiplication);
12+
13+
let division = 100 / 5;
14+
console.log("Division: 10 / 5 = ", division);
15+
16+
let _module = 8 % 2;
17+
console.log("Module: 8 % 2 = ", _module);
18+
19+
let power = 4 ** 2;
20+
console.log("Power: 4 ** 2 = ", power);
21+
22+
// Assignment Operators
23+
let a = 10;
24+
25+
a += 2;
26+
console.log("Addition assignment +=: ", a);
27+
28+
a -= 2;
29+
console.log("Subtraction assignment -=: ", a);
30+
31+
a *= 4;
32+
console.log("Multiplication assignment *=: ", a);
33+
34+
a /= 2;
35+
console.log("Division assignment /=: ", a);
36+
37+
a %= 2;
38+
console.log("Remainder assignment %=: ", a);
39+
40+
a **= 2;
41+
console.log("Exponentiation assignment **=: ", a);
42+
43+
// Comparison Operators
44+
console.log("Equality == : ", 5 == "5");
45+
console.log("Strict equality == : ", 5 === "5");
46+
console.log("Inequality != : ", 5 != "5");
47+
console.log("Strict inequality !== : ", 5 !== "5");
48+
console.log("Greater than > : ", 10 > 5);
49+
console.log("Less than < : ", 10 < 5);
50+
console.log("Greater than or equal >= : ", 5 >= 7);
51+
console.log("Less than or equal <= : ", 5 <= 7);
52+
53+
// Logical Operators
54+
console.log("Logical AND (&&):", true && false);
55+
console.log("Logical OR (||):", true || false);
56+
console.log("Logical NOT (!):", !false);
57+
58+
// Identity Operators
59+
let obj1 = { name: "Isaac" };
60+
let obj2 = { name: "Isaac" };
61+
let obj3 = obj1;
62+
console.log("Identity (===):", obj1 === obj2);
63+
console.log("Identity (===):", obj1 === obj3);
64+
65+
// Membership Operators
66+
let array = [1, 2, 3, 4, 5];
67+
console.log("Membership (in):", 3 in array);
68+
console.log("Membership (includes):", array.includes(3));
69+
70+
let obj = { name: "Bob", age: 25 };
71+
console.log("Membership (in):", "name" in obj);
72+
console.log("Membership (in):", "height" in obj);
73+
74+
// Bits Operators
75+
console.log("Bitwise AND (&):", 5 & 1); // 101 & 001 = 001 (1)
76+
console.log("Bitwise OR (|):", 5 | 1); // 101 | 001 = 101 (5)
77+
console.log("Bitwise XOR (^):", 5 ^ 1); // 101 ^ 001 = 100 (4)
78+
console.log("Bitwise NOT (~):", ~5); // ~101 = 010 (complemento)
79+
console.log("Bitwise Left Shift (<<):", 5 << 1); // 101 << 1 = 1010 (10)
80+
console.log("Bitwise Right Shift (>>):", 5 >> 1); // 101 >> 1 = 010 (2)
81+
console.log("Bitwise Zero-fill Right Shift (>>>):", 5 >>> 1); // 101 >>> 1 = 010 (2)
82+
83+
// Control Structures //
84+
85+
// Conditionals
86+
let num = 10;
87+
if (num > 0) {
88+
console.log("The number is positive");
89+
} else if (num < 0) {
90+
console.log('The number is negative');
91+
} else {
92+
console.log('The number is cero');
93+
}
94+
95+
switch (num) {
96+
case 1:
97+
console.log('The number is 1');
98+
break;
99+
case 10:
100+
console.log('The numer is 10')
101+
break;
102+
default:
103+
console.log('The number is not 1 or 10');
104+
}
105+
106+
// Iterative
107+
for (let i = 0; i < 5; i++) {
108+
console.log('For loop, i = ', i);
109+
}
110+
111+
let count = 0;
112+
while (count < 5) {
113+
console.log('While loop, i = ', count);
114+
count++;
115+
}
116+
117+
let index = 0;
118+
do {
119+
console.log('Do loop, index = ', index);
120+
index++;
121+
} while (index < 5);
122+
123+
let arrayForOf = ['a', 'b', 'c'];
124+
for (let item of arrayForOf) {
125+
console.log('For-of loop, item = ', item);
126+
}
127+
128+
let objForIn = { name: 'Alice', age: 25};
129+
for (let key in objForIn) {
130+
console.log('For-in loop, key = ', key, ', value = ', objForIn[key]);
131+
}
132+
133+
// Exceptions
134+
try {
135+
let result = 10 / 0;
136+
console.log('Result: ', result);
137+
throw new Error('This is a custom exception');
138+
} catch (error) {
139+
console.log('An exception was caught: ', error.message);
140+
} finally {
141+
console.log('This block is always executed');
142+
}
143+
144+
// Extra Exercise //
145+
146+
for (let i = 10; i <= 55 ; i++) {
147+
if (i % 2 === 0 && i % 3 !== 0 && i !== 16) {
148+
console.log(i);
149+
}
150+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Exercise //
2+
// Function whitout parameters or return value
3+
function noParameters() {
4+
console.log("This function has no parameters or return value.");
5+
}
6+
7+
noParameters();
8+
9+
// Function with one parameter
10+
function oneParameter(param) {
11+
console.log("The received parameter is: " + param);
12+
}
13+
14+
oneParameter("Hello World");
15+
16+
// Function with multiple parameters
17+
function multipleParameters(param1, param2) {
18+
console.log("The received parameters are: " + param1 + " and " + param2);
19+
}
20+
21+
multipleParameters('Hello', 'World');
22+
23+
// Function with return value
24+
function addition(a, b) {
25+
return console.log(a + b);
26+
}
27+
28+
addition(4, 10);
29+
30+
// Nested functions
31+
function outerFunction() {
32+
console.log("This is the outer function");
33+
function innerFunction() {
34+
console.log("This is the inner function");
35+
}
36+
innerFunction();
37+
}
38+
39+
outerFunction();
40+
41+
// Using built-in functions
42+
function exampleMath() {
43+
console.log("The absolute value of -5 is: " + Math.abs(-5));
44+
}
45+
46+
exampleMath();
47+
48+
// Local and global variables
49+
var globalVar = "I am a global variable";
50+
51+
function variableScope() {
52+
var localVar = "I am a local variable";
53+
console.log(globalVar);
54+
console.log(localVar);
55+
}
56+
57+
variableScope();
58+
console.log(globalVar);
59+
// The following line will throw an error because 'localVar' is not defined in the global scope
60+
// console.log(localVar);
61+
62+
// Extra Exercise //
63+
64+
function oneHundred(param1, param2) {
65+
let counter = 0;
66+
67+
for (let i = 1; i <= 100; i++) {
68+
if (i % 3 === 0 && i % 5 === 0) {
69+
console.log(param1, param2);
70+
} else if (i % 3 === 0) {
71+
console.log(param1);
72+
} else if (i % 5 === 0) {
73+
console.log(param2);
74+
} else {
75+
console.log(i);
76+
counter++;
77+
}
78+
}
79+
return counter;
80+
}
81+
82+
const counter = oneHundred('Fizz', 'Buzz');
83+
console.log("Count of numbers printed: " + counter);

0 commit comments

Comments
 (0)