-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (42 loc) · 1.46 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require("express");
const app = express();
const http = require("http").createServer(app);
const fs = require("fs");
var words = fs.readFileSync("randomwords.txt","utf8");
words = words.split('\n');
app.get('/', function(req,res) {
var wordamt = req.query.amount;
if(wordamt == undefined) {
res.send(`<!DOCTYPE HTML>
<html><body><head><title>Random Words Generator</title><style>
body{
font-family: Calibri;
color: #230096;
font-size: 2em;
background-color: #b8a1ff; background-image: url(background.jpg);
}
a{
color: #96005a;
text-decoration: none;
}
a:hover{
text-decoration:underline;
}
</style></head>
<center><h2>Random Words Generator by SilentSerenity</h2><br>
This Javascript code was made as a fun project, and it generates random words. How it works is that after this link, type in "/?amount=x", where "x" must be equal to an integer.<br><br>
You can use this one as a test, it will generate 7 random words!<br><a href="https://Random-Words-Generator.silentserenity.repl.co/?amount=7">Generate seven Random Words!!</a></body></html>`);
} else {
res.send(RandomWordGenerator(wordamt))
}
})
function RandomWordGenerator(amt){
let randomword = "Here are the Random Words!\t";
for(let x = 0 ; x < amt ; x++) {
randomword += words[Math.floor(Math.random()*words.length)];
}
return randomword;
}
http.listen(8080,function(){
console.log("Random Words Generation is a go!");
})