So, i have been sitting on this exercise for a few hours now. Even though the code editor shows 0 errors, when I execute the following code in web browser it returns the error TypeError: Cannot read property 'skyColor' of undefined
and the console returns the error POST http://localhost:3000/answer 500 (Internal Server Error)
. Can someone kindly help me out
let express = require("express");
let our_app= express();
our_app.get(express.urlencoded({extended:false}));
our_app.get("/", function(req,res){
res.send(`
<form action="/answer" method="POST">
<h1>What color is the sky on a clear bight day???</h1>
<input type="text" autocomplete="off" name="skyColor">
<button type="submit">Submit Answer</button>
</form>
`)
});
our_app.get("/answer", function(req,res){
res.send("Sorry, you are not permitted to access this page")
});
our_app.post("/answer", function(req,res){
if(req.body.skyColor.toUpperCase()=="BLUE"){
res.end(`<p>Congratulations, You guessed the answer right</p>
<a href="/">Go back to Home Page</a>
`);
} else{
res.end(`<p>Congratulations, You guessed the answer right</p>
<a href="/">Go back to Home Page</a>
`);
}
});
our_app.listen(3000);