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

Dzień 5 #6

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 14 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
//Twój kod
//Twój kod
const express = require('express');
const app = express();

app.use(express.static('/'));

app.get('/:number1/:number2', (req, res) => {
const number1 = req.params.number1;
const number2 = req.params.number2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Można by ew. już przy deklaracji zmiennych dać parseInt.

res.send(`Suma ${number1} i ${number2} to: ` + (parseInt(number1)+parseInt(number2)));
});
app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
29 changes: 28 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
//Twój kod
//Twój kod
const express = require('express');
const app = express();

var name =""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Używamy raczej let.

app.use(express.static('/'));

app.get('/name/set/:imie', (req, res) => {
name = req.params.imie;
res.send('Witaj, ' + name);
});
app.get('/name/show', (req, res) => {
res.send('Imię: ' + name);
});


app.get('/name/check', (req, res) => {
if(name.length>0){
res.send('Imię: ' + name)
}else{
res.send("nie podano imienia")
}
});


app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});``
31 changes: 30 additions & 1 deletion app/zadanieDnia1.js
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
//Twój kod
//Twój kod
const express = require('express');
const app = express();

var counterYes = 0;
var counterNo = 0;
var counterMaybe=0;
app.use(express.static('./public/zadanieDnia/'));

app.get(`/vote/:selected`, (req, res) => { //np. localhost:3000/hello/Programist(k)o
const vote = req.params.selected;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bardzo eleganckie rozwiązanie

res.send('Zagłosowano ' + vote);
if(vote!==null){
if(vote==='yes'){
counterYes++
}else if(vote==='no'){
counterNo++
}else{
counterMaybe++
}
}

});
app.get('/votes/check', (req,res)=>{
res.send(`Zagłosowano: ${counterYes} głosów na tak; ${counterNo} głosów na nie; ${counterMaybe} głosów na Nie wiem`)
})

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
Loading