Skip to content
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
9 changes: 8 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
//Twój kod
const express = require("express");
const app = express();

app.get("/:number1/:number2", (req, res) => {
res.send( (parseInt(req.params.number1)+parseInt(req.params.number2)).toString() );
});

app.listen(3000);
30 changes: 29 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
//Twój kod
const express = require("express");
const app = express();

let name;
const not_defined = "Imię nie zostało zdefiniowane";

app.get("/set/:name", (req, resp) => {
name = req.params.name;
resp.send("Ustawiono imię!");
});

app.get("/name/show", (req, resp) => {
let responseText = not_defined;
if (typeof name !== 'undefined') {
responseText = "Imię to: " + name;
}
resp.send(responseText);
});

app.get("/name/check", (req, resp) => {
if (typeof name === 'undefined') {
resp.send(not_defined);
}
else {
resp.send("Imię jest ustawione");
}
});

app.listen(3000);
35 changes: 34 additions & 1 deletion app/zadanieDnia1.js
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
//Twój kod
const express = require("express");
const app = express();

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

let answers = [];

app.get("/vote/:answer", (req, resp) => {
const answer = req.params.answer;
if (typeof answers[answer] === 'undefined') {
answers[answer] = 1;
}
else {
answers[answer]++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Brawo, uniwersalne


resp.send("Dziekujemy za głos na " + answer + ". Aktualnie posiada on: " + answers[answer] + " głosów.");
});

app.get("/votes/check", (req, resp) => {
let answer = "Wyniki ankiety: <ul>";

for (let index in answers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Super

if (answers.hasOwnProperty(index)) {
answer += "<li>" + index + " - głosów " + answers[index] + "</li>"
}
}

answer += "</ul>";

resp.send(answer);
});

app.listen(3000);