Skip to content

Commit

Permalink
Merge pull request mouredev#5991 from Sac-Corts/main
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
Roswell468 authored Sep 7, 2024
2 parents 699a33a + bca803b commit 3399049
Show file tree
Hide file tree
Showing 31 changed files with 2,713 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// JavaScript programming language official website URL:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript

// Single line comment in JavaScript

/*
Multi-line comment in JavaScript
It is used to describe longer blocks of code.
or provide detailed information.
*/

var myGlobalVariable = "This is a global variable"

let myLocalVariable = "This is a local variable";

const MY_CONSTANT = "This is a constant";

// String
let textString = "Hello, I am a string";
console.log(typeof(textString))

// Number
let integer = 42;
console.log(typeof(integer))

let float = 3.14;
console.log(typeof(float))

// Boolean
let boolean = true;
console.log(typeof(boolean))

// Undefined
let undefinedVar;
console.log(typeof(undefinedVar))

// Null
let nullVar = null;
console.log(typeof(nullVar))

// Symbol
let symbol = Symbol('description');
console.log(typeof(symbol))

// BigInt
let bigInt = BigInt(1234567890123456789012345678901234567890n);
console.log(typeof(bigInt))

// Print the required text via terminal
console.log("¡Hello, JavaScript!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Exercise //

// Arithmetic Operators
let addition = 5 + 3;
console.log("Addition: 5 + 3 = ", addition);

let subtraction = 10 - 5;
console.log("Subtraction: 10 - 5 = ", subtraction);

let multiplication = 10 * 5;
console.log("Multiplication: 10 * 5 = ", multiplication);

let division = 100 / 5;
console.log("Division: 10 / 5 = ", division);

let _module = 8 % 2;
console.log("Module: 8 % 2 = ", _module);

let power = 4 ** 2;
console.log("Power: 4 ** 2 = ", power);

// Assignment Operators
let a = 10;

a += 2;
console.log("Addition assignment +=: ", a);

a -= 2;
console.log("Subtraction assignment -=: ", a);

a *= 4;
console.log("Multiplication assignment *=: ", a);

a /= 2;
console.log("Division assignment /=: ", a);

a %= 2;
console.log("Remainder assignment %=: ", a);

a **= 2;
console.log("Exponentiation assignment **=: ", a);

// Comparison Operators
console.log("Equality == : ", 5 == "5");
console.log("Strict equality == : ", 5 === "5");
console.log("Inequality != : ", 5 != "5");
console.log("Strict inequality !== : ", 5 !== "5");
console.log("Greater than > : ", 10 > 5);
console.log("Less than < : ", 10 < 5);
console.log("Greater than or equal >= : ", 5 >= 7);
console.log("Less than or equal <= : ", 5 <= 7);

// Logical Operators
console.log("Logical AND (&&):", true && false);
console.log("Logical OR (||):", true || false);
console.log("Logical NOT (!):", !false);

// Identity Operators
let obj1 = { name: "Isaac" };
let obj2 = { name: "Isaac" };
let obj3 = obj1;
console.log("Identity (===):", obj1 === obj2);
console.log("Identity (===):", obj1 === obj3);

// Membership Operators
let array = [1, 2, 3, 4, 5];
console.log("Membership (in):", 3 in array);
console.log("Membership (includes):", array.includes(3));

let obj = { name: "Bob", age: 25 };
console.log("Membership (in):", "name" in obj);
console.log("Membership (in):", "height" in obj);

// Bits Operators
console.log("Bitwise AND (&):", 5 & 1); // 101 & 001 = 001 (1)
console.log("Bitwise OR (|):", 5 | 1); // 101 | 001 = 101 (5)
console.log("Bitwise XOR (^):", 5 ^ 1); // 101 ^ 001 = 100 (4)
console.log("Bitwise NOT (~):", ~5); // ~101 = 010 (complemento)
console.log("Bitwise Left Shift (<<):", 5 << 1); // 101 << 1 = 1010 (10)
console.log("Bitwise Right Shift (>>):", 5 >> 1); // 101 >> 1 = 010 (2)
console.log("Bitwise Zero-fill Right Shift (>>>):", 5 >>> 1); // 101 >>> 1 = 010 (2)

// Control Structures //

// Conditionals
let num = 10;
if (num > 0) {
console.log("The number is positive");
} else if (num < 0) {
console.log('The number is negative');
} else {
console.log('The number is cero');
}

switch (num) {
case 1:
console.log('The number is 1');
break;
case 10:
console.log('The numer is 10')
break;
default:
console.log('The number is not 1 or 10');
}

// Iterative
for (let i = 0; i < 5; i++) {
console.log('For loop, i = ', i);
}

let count = 0;
while (count < 5) {
console.log('While loop, i = ', count);
count++;
}

let index = 0;
do {
console.log('Do loop, index = ', index);
index++;
} while (index < 5);

let arrayForOf = ['a', 'b', 'c'];
for (let item of arrayForOf) {
console.log('For-of loop, item = ', item);
}

let objForIn = { name: 'Alice', age: 25};
for (let key in objForIn) {
console.log('For-in loop, key = ', key, ', value = ', objForIn[key]);
}

// Exceptions
try {
let result = 10 / 0;
console.log('Result: ', result);
throw new Error('This is a custom exception');
} catch (error) {
console.log('An exception was caught: ', error.message);
} finally {
console.log('This block is always executed');
}

// Extra Exercise //

for (let i = 10; i <= 55 ; i++) {
if (i % 2 === 0 && i % 3 !== 0 && i !== 16) {
console.log(i);
}
}
83 changes: 83 additions & 0 deletions Roadmap/02 - FUNCIONES Y ALCANCE/javascript/Sac-Corts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Exercise //
// Function whitout parameters or return value
function noParameters() {
console.log("This function has no parameters or return value.");
}

noParameters();

// Function with one parameter
function oneParameter(param) {
console.log("The received parameter is: " + param);
}

oneParameter("Hello World");

// Function with multiple parameters
function multipleParameters(param1, param2) {
console.log("The received parameters are: " + param1 + " and " + param2);
}

multipleParameters('Hello', 'World');

// Function with return value
function addition(a, b) {
return console.log(a + b);
}

addition(4, 10);

// Nested functions
function outerFunction() {
console.log("This is the outer function");
function innerFunction() {
console.log("This is the inner function");
}
innerFunction();
}

outerFunction();

// Using built-in functions
function exampleMath() {
console.log("The absolute value of -5 is: " + Math.abs(-5));
}

exampleMath();

// Local and global variables
var globalVar = "I am a global variable";

function variableScope() {
var localVar = "I am a local variable";
console.log(globalVar);
console.log(localVar);
}

variableScope();
console.log(globalVar);
// The following line will throw an error because 'localVar' is not defined in the global scope
// console.log(localVar);

// Extra Exercise //

function oneHundred(param1, param2) {
let counter = 0;

for (let i = 1; i <= 100; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log(param1, param2);
} else if (i % 3 === 0) {
console.log(param1);
} else if (i % 5 === 0) {
console.log(param2);
} else {
console.log(i);
counter++;
}
}
return counter;
}

const counter = oneHundred('Fizz', 'Buzz');
console.log("Count of numbers printed: " + counter);
Loading

0 comments on commit 3399049

Please sign in to comment.