diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de88951 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*.*~ +node_modules diff --git a/app/public/zadanieDnia/css/style.css b/app/public/zadanieDnia/css/style.css index b0708de..fac86a8 100644 --- a/app/public/zadanieDnia/css/style.css +++ b/app/public/zadanieDnia/css/style.css @@ -11,4 +11,8 @@ .vote.no { background : red; +} + +.vote.maybe { + background: hotpink; } \ No newline at end of file diff --git a/app/public/zadanieDnia/index.html b/app/public/zadanieDnia/index.html index bfc2842..5172239 100644 --- a/app/public/zadanieDnia/index.html +++ b/app/public/zadanieDnia/index.html @@ -12,6 +12,7 @@

Zagłosuj: czy Node.js jest fajny?

Tak! Nie :( + To się okaże
Sprawdź wyniki głosowania diff --git a/app/test.js b/app/test.js new file mode 100644 index 0000000..1415549 --- /dev/null +++ b/app/test.js @@ -0,0 +1,10 @@ +const express = require('express'); +const app = express(); + +app.get('/', (req, res) => { + res.send('Hello, World!'); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file diff --git a/app/test2.js b/app/test2.js new file mode 100644 index 0000000..e974e57 --- /dev/null +++ b/app/test2.js @@ -0,0 +1,8 @@ +const express = require('express'); +const app = express(); + +app.use(express.static('./public/przykladStatyczne/')); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..0220ec7 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,13 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const app = express(); + +app.get('/:num1/:num2', (req, res) => { + const num1 = req.params.num1; + const num2 = req.params.num2; + let sum = parseInt(num1) + parseInt(num2); + res.send('Suma liczb to ' + sum); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..3675875 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,20 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const app = express(); +let userName = ''; + +app.get('/name/set/:imie', (req, res) => { + userName = req.params.imie; +res.send('Twoje imię to ' + userName); +}); + +app.get('/name/show', (req, res) => { + res.send('Zapamiętałem Twoje imię: ' + userName); +}); + +app.get('/name/check', (req, res) => { + (userName !=='')? (res.send('Zapamiętałem Twoje imię: ' + userName)) : (res.send('Nie znam Twojego imienia :(')); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file diff --git a/app/zadanieDnia1.js b/app/zadanieDnia1.js index 8c20173..e971a16 100644 --- a/app/zadanieDnia1.js +++ b/app/zadanieDnia1.js @@ -1 +1,20 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const app = express(); +let yesCounter = 0; +let noCounter = 0; +let maybeCounter = 0; +app.use(express.static('./public/zadanieDnia/')); +let pollCounter = ()=> { + app.get('/vote/:votetype', (req, res) => { + let votetype = req.params.votetype; + (votetype === 'yes') ? yesCounter++ : (votetype === 'no')? noCounter++ : maybeCounter++; + res.send('Dziękujemy za głos!'); + }); + app.get('/votes/check', (req, res) => { + res.send(`'Tak': ${yesCounter} 'Nie': ${noCounter} 'To się okaże': ${maybeCounter}`); + }); + }; +pollCounter(); +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b4292aa --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "challenge", + "version": "1.0.0", + "description": "\"Logo\"", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/angorzan/Node.js_challenge_dzien_5.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/angorzan/Node.js_challenge_dzien_5/issues" + }, + "homepage": "https://github.com/angorzan/Node.js_challenge_dzien_5#readme", + "dependencies": { + "express": "^4.16.2" + } +}