Skip to content

Commit da31222

Browse files
committed
Introduction to JavaScript
1 parent 7f8b13a commit da31222

17 files changed

Lines changed: 128 additions & 0 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Repository with several projects and programming exercises in Python and SQL car
2020
* [SQL - Introduction](./SQL_introduction)
2121
* [SQL - More queries](./SQL_more_queries)
2222
* [Python - Object-relational mapping](./python-object_relational_mapping)
23+
* [JavaScript - Warm up](./javascript-warm_up)
2324

2425
## Author
2526
* Felipe Villamizar - [GitHub](https://github.com/felipevcc)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/node
2+
// Prints a str
3+
const myVar = 'JavaScript is amazing';
4+
console.log(myVar);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/node
2+
// Prints 3 lines
3+
console.log('C is fun');
4+
console.log('Python is cool');
5+
console.log('JavaScript is amazing');

javascript-warm_up/10-factorial.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/node
2+
// Computes and prints a factorial
3+
const num = parseInt(process.argv[2]);
4+
function factorial (n) {
5+
if (!n) {
6+
return 1;
7+
} else {
8+
return n * factorial(n - 1);
9+
}
10+
}
11+
console.log(factorial(num));
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/node
2+
// Searches the secord biggest integer in args
3+
const args = process.argv.slice(2);
4+
if (args.length < 2) {
5+
console.log(0);
6+
} else {
7+
let biggest = Number.MIN_SAFE_INTEGER;
8+
let secBiggest = Number.MIN_SAFE_INTEGER;
9+
for (let i = 0; i < args.length; i++) {
10+
const num = parseInt(args[i]);
11+
if (num > biggest) {
12+
secBiggest = biggest;
13+
biggest = num;
14+
} else if (num > secBiggest) {
15+
secBiggest = num;
16+
}
17+
}
18+
console.log(secBiggest);
19+
}

javascript-warm_up/12-object.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/node
2+
// Replace a value in myObject
3+
const myObject = {
4+
type: 'object',
5+
value: 12
6+
};
7+
console.log(myObject);
8+
9+
myObject.value = 89;
10+
11+
console.log(myObject);

javascript-warm_up/13-add.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/node
2+
// Export a function that returns an addition
3+
exports.add = function (a, b) {
4+
return a + b;
5+
};

javascript-warm_up/13-main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/node
2+
// Call a function that is in another file
3+
const add = require('./13-add').add;
4+
console.log(add(3, 5));

javascript-warm_up/2-arguments.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/node
2+
// Prints a msg depending of the number of args passed
3+
const args = process.argv;
4+
if (args.length === 3) {
5+
console.log('Argument found');
6+
} else if (args.length > 3) {
7+
console.log('Arguments found');
8+
} else {
9+
console.log('No argument');
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/node
2+
// Prints the first argument passed
3+
const args = process.argv;
4+
if (args[2]) {
5+
console.log(args[2]);
6+
} else {
7+
console.log('No argument');
8+
}

0 commit comments

Comments
 (0)