forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#6316 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 - TypeScript
- Loading branch information
Showing
31 changed files
with
2,695 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Roadmap/00 - SINTAXIS, VARIABLES, TIPOS DE DATOS Y HOLA MUNDO/typescript/Sac-Corts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// https://www.typescriptlang.org/ | ||
// Single-line comment | ||
|
||
/* | ||
* Multi-line comment | ||
* Explaining the purpose of the code | ||
* or any other revelant information | ||
*/ | ||
|
||
// Declaring a variable | ||
let language: string = "TypeScript"; | ||
|
||
// Declaring a constant | ||
const version: string = "5.5.4"; | ||
|
||
// Declaring variables representing different primitive data types | ||
let text: string = "This is a string"; // String | ||
let number: number = 43; // Number (integer or decimal) | ||
let boolean: boolean = true; // Boolean | ||
|
||
// Undefined and null are also considered types in TypeScript | ||
let undefinedVar: undefined = undefined; //Undefined | ||
let nullVar: null = null; // Null | ||
|
||
console.log(`Hello, ${language}!`); |
118 changes: 118 additions & 0 deletions
118
Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/typescript/Sac-Corts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Arithmetic Operators | ||
let c: number = 10; | ||
let b: number = 5; | ||
console.log("Addition:", c + b); | ||
console.log("Subtraction:", c - b); | ||
console.log("Multiplication:", c * b); | ||
console.log("Division:", c / b); | ||
console.log("Modulus:", c % b); | ||
console.log("Exponentiation:", c ** b); | ||
|
||
// Logical Operators | ||
let isTrue: boolean = true; | ||
let isFalse: boolean = false; | ||
console.log("AND (&&):", isTrue && isFalse); | ||
console.log("OR (||):", isTrue || isFalse); | ||
console.log("NOT (!):", !isTrue); | ||
|
||
// Comparison Operators | ||
console.log("Equal (==):", c == b); | ||
console.log("Not equal (!=):", c != b); | ||
console.log("Strict equal (===):", c === b); | ||
console.log("Strict not equal (!==):", c !== b); | ||
console.log("Greater than (>):", c > b); | ||
console.log("Less than (<):", c < b); | ||
console.log("Greater than or equal (>=):", c >= b); | ||
console.log("Less than or equal (<=):", c <= b); | ||
|
||
// Assignment Operators | ||
let x: number = 10; | ||
x += 5; | ||
console.log("x after x += 5:", x); | ||
x -= 3; | ||
console.log("x after x -= 5:", x); | ||
x *= 2; | ||
console.log("x after x *= 2:", x); | ||
x /= 4; | ||
console.log("x after x /= 4:", x); | ||
x **= 2; | ||
console.log("x after x **= 2:", x); | ||
x %= 2; | ||
console.log("x after x %= 2:", x); | ||
|
||
// Bitwise Operators | ||
let bitA: number = 5; // Binary: 0101 | ||
let bitB: number = 3; // Binary: 0011 | ||
console.log("Bitwise AND(&):", bitA & bitB); | ||
console.log("Bitwise OR(|):", bitA | bitB); | ||
console.log("Bitwise XOR(^):", bitA ^ bitB); | ||
console.log("Bitwise NOT(~):", ~bitA); | ||
console.log("Left shift(<<):", bitA << 1); | ||
console.log("Right shift(>>):", bitA >> 1); | ||
|
||
// Control Structures // | ||
// If-else statement | ||
if (c > b) { | ||
console.log("c is greater than b"); | ||
} else { | ||
console.log("c is not greater than b"); | ||
} | ||
|
||
// Ternary Operator | ||
let max = c > b ? c : b; | ||
console.log("Max value:", max); | ||
|
||
// Switch-case statement | ||
let day: number = 2; | ||
switch(day) { | ||
case 1: | ||
console.log("It's Monday"); | ||
break; | ||
case 2: | ||
console.log("It's Tuesday"); | ||
break; | ||
case 3: | ||
console.log("It's Wednesday"); | ||
break; | ||
} | ||
|
||
// While loop | ||
let _count: number = 0; | ||
while (_count < 3) { | ||
console.log("While loop count:", _count); | ||
_count++; | ||
} | ||
|
||
// For loop | ||
for (let i = 0; i < 3; i++) { | ||
console.log("For loop iteration:", i); | ||
} | ||
|
||
// Do-while loop | ||
let doCount: number = 0; | ||
do { | ||
console.log("Do-while loop count:", doCount); | ||
doCount++; | ||
} while (doCount < 3); | ||
|
||
// Try-catch (Exception Handling) | ||
try { | ||
let result = c / 0; | ||
if (!isFinite(result)) { | ||
throw new Error("Cannot divide by zero"); | ||
} | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.log(error.message); | ||
} | ||
} finally { | ||
console.log("Finally block executed"); | ||
} | ||
|
||
// *** Extra Exercise *** // | ||
|
||
for (let i = 10; i <= 55; i++) { | ||
if (i % 2 == 0 && i % 3 !== 0 && i !== 16) { | ||
console.log(i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Function with no parameters and no return | ||
function greet(): void { | ||
console.log("Hello, welcome to TypeScript!"); | ||
} | ||
|
||
// Function with one parameter and no return | ||
function greetUser(name: string): void { | ||
console.log(`Hello, ${name}!`); | ||
} | ||
|
||
// Function with multiple parameters and no return | ||
function addNumbers(a: number, b: number): void { | ||
console.log(`The sum of ${a} and ${b} is ${a + b}`); | ||
} | ||
|
||
// Function with one parameter and a return value | ||
function square(num: number): number { | ||
return num * num; | ||
} | ||
|
||
// Function with multiple parameters and a return value | ||
function multiplyNumbers(a: number, b: number): number { | ||
return a * b; | ||
} | ||
|
||
// Nested Functions | ||
function outerFunction(): void { | ||
console.log("This is the outer function"); | ||
|
||
// Inner function | ||
function innerFunction(): void { | ||
console.log("This is the inner function"); | ||
} | ||
|
||
innerFunction(); | ||
} | ||
|
||
// Built-in Functions | ||
function calculateCircleArea(radius: number): number { | ||
return Math.PI * Math.pow(radius, 2); | ||
} | ||
|
||
// Testing local and global variables | ||
// Global variable | ||
let globalVar = "I'm a global variable"; | ||
|
||
function testVariableScope(): void { | ||
// Local variable | ||
let localVar = "I'm a local variable"; | ||
|
||
console.log(globalVar); | ||
console.log(localVar); | ||
|
||
globalVar = "Global variable modified inside the function"; | ||
} | ||
|
||
greet(); // Function without parameters and no return | ||
greetUser("Isaac"); // Function with one parameter and no return | ||
addNumbers(5, 7); // Function with multiple parameters and no return | ||
console.log(`Square of 4 is: ${square(4)}`); // Function with one parameter and return value | ||
console.log(`Multiplication of 3 and 6 is: ${multiplyNumbers(3, 6)}`); // Function with multiple parameters and return value | ||
|
||
outerFunction(); // Calls outer and inner function | ||
|
||
console.log(`Area of circle with radius 5 is: ${calculateCircleArea(5)}`); // Uses Math functions | ||
|
||
testVariableScope(); | ||
console.log(globalVar); | ||
// console.log(localVar); Error: localVar is not defined outside the function | ||
|
||
|
||
// *** Extra Exercise *** // | ||
function printNumbersWithText(string1: string, string2: string): number { | ||
let counter = 0; | ||
|
||
for (let i = 1; i <= 100; i++) { | ||
if (i % 3 === 0 && i % 5 === 0) { | ||
console.log(string1 + string2); | ||
} else if (i % 3 === 0) { | ||
console.log(string1); | ||
} else if (i % 5 === 0) { | ||
console.log(string2); | ||
} else { | ||
console.log(i); | ||
counter++; | ||
} | ||
} | ||
return counter; | ||
} | ||
|
||
const times = printNumbersWithText("Fizz", "Buzz"); | ||
console.log(`The number was printed ${times} times`); |
Oops, something went wrong.