Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node conection #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ git add .
git commit -m "done"
git push -u origin master
```
- Crea el Pull Request desde GitHub.
- Crea el Pull Request desde GitHub.


<!-- Interracion con el usuario -->
readlineSync
npm i -S readline.sync
1 change: 1 addition & 0 deletions starter-code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
38 changes: 38 additions & 0 deletions starter-code/calculadora.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Install code
const readLineSync = require('readline-sync')
const {sum, res, mul, div} = require('./math')

const operations =['sum', 'res', 'mul', 'div'];
const index = readLineSync.keyInSelect(operations, 'Which operation do you want?');

let firstNumber
let secondNumber

if (index !== -1) {
firstNumber = readLineSync.questionInt('Input fisrt number: ');
secondNumber = readLineSync.questionInt('Input second number: ');
}



switch(index){
case 0:
console.log(sum(firstNumber, secondNumber));
break;
case 1:
console.log(res(firstNumber, secondNumber));
break;

case 2:
console.log(mul(firstNumber, secondNumber));
break;

case 3:
console.log(div(firstNumber, secondNumber));
break;

default:
console.log('Nothing');
}


11 changes: 9 additions & 2 deletions starter-code/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// Initial code
console.log('Welcome to Node.js');
const http = require('http');

//Creating server
http.createServer((req, res) =>{
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<p>Bienvenido a node.js </p><h2>subtitle</h2>');
}).listen('8080');

console.log('Node aplication listening on port 8080');
18 changes: 18 additions & 0 deletions starter-code/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Sum
const sum = (x, y) => x+y;

// Resta
const res = (x,y) => x-y;

// Multiplicacion
const mul = (x,y) => x*y;

// Division
const div = (x,y) => x/y;

module.exports = {
sum,
res,
mul,
div
};
22 changes: 22 additions & 0 deletions starter-code/node_modules/readline-sync/LICENSE-MIT

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions starter-code/node_modules/readline-sync/README-Deprecated.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading