A Repl by Christonja on Repl.it.
My own solutions to an assignment provided by the Web Developer Bootcamp on Udemy, ran by Colt Steele
A Repl by Christonja on Repl.it.
My own solutions to an assignment provided by the Web Developer Bootcamp on Udemy, ran by Colt Steele
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const db = require('./db'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(express.static('public')); | |
app.get("/", function(req, res) { | |
res.send("Hi there, welcome to my assignment!"); | |
}); | |
app.get("/speak/:animal", function(req, res) { | |
var animal = req.params.animal; | |
var says = (animal == "pig") ? "Oink" : (animal == "cow") ? "Moo" : (animal == "dog") ? "Woof Woof!" : "Huh!?"; | |
res.send("The " + animal + " says" + " '" + says + "'"); | |
}); | |
app.get("/repeat/:random/:num", function(req, res){ | |
var random = req.params.random; | |
var num = Number(req.params.num); | |
var str = ""; | |
for (var i = 0; i < num; i++) { | |
str += " " + random; | |
} | |
str == "" ? str = "Usage: 'http://localhost:3000/repeat/:random/5' where '5' could be any positive integer" : ""; | |
res.send(str); | |
}) | |
app.get("*", function(req, res) { | |
res.send("Sorry, page not found... What are you doing with your life?"); | |
}) | |
app.listen(3000, () => console.log('server started')); |