Var Express Require Express Var Cookieparser Require Cookie Parser Var Session Require Exp Q37157443

(3 points) Task 3.2 Implement a basic webpage that displays a Level 1 heading containing the name of a colour, displayed in t

last.js colour.js colour.html task1.js 1 var expressrequire(express); 2 var cookieParser require(cookie-parser); 3 var ses

var express = require(‘express’);
var cookieParser = require(‘cookie-parser’);
var session = require(‘express-session’);

var app = express();

app.use(cookieParser());
app.use(session({secret: “Shh, its a secret!”}));

app.get(‘/colour.html’, function(req, res){
if(req.session.page_views == 0){
req.session.page_views++;
res.send(“Red”);

}

else if(req.session.page_views == 1){
req.session.page_views++;
res.send(“Yellow”);
}
else if(req.session.page_views == 2){
req.session.page_views++;
res.send(“Green”);
}
else if(req.session.page_views == 3){
req.session.page_views++;
res.send(“Blue”);
}

else if(req.session.page_views == 4){
req.session.page_views = 0;
res.send(“Red”);
}

});
app.listen(3000);

//Pic below are the codes to index,js, codes from the questionabove are to be added into this file, dont modify the firstrouter.get function, leave it

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.