-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserv.js
More file actions
38 lines (29 loc) · 878 Bytes
/
Copy pathserv.js
File metadata and controls
38 lines (29 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
app.use(express.static('./'));
app.use(bodyParser.json());
const randomNum = () => {
return Math.floor(Math.random() * 10000);
}
const randomNumber = randomNum()
console.log(randomNumber);
app.post('/add', (req, res) => {
const num = req.body.num;
let text = ''
if(num == randomNumber) {
text = "Twoja liczba to: " + num + ". Zgadłeś wylosowaną liczbę"
}
else if (num < randomNumber) {
text = "Twoja liczba to: " + num + ". Podana przez Ciebie liczba jest mniejsza od wylosowanej"
}
else {
text = "Twoja liczba to: " + num + ". Podana przez Ciebie liczba jest większa od wylosowanej"
}
res.json({
text, randomNumber
});
})