<file_sep>var score = 0;
var quiz = {
    questions : [
        {
            questionNumber : "Question 1",
            questionText: "Which of the following sorts is stable and inplace?",
            choice : [
                {
                    text : "Merge Sort",
                    isCorrect : false,
                    feedback : "Wrong Answer"
                },
                {
                    text : "Quick Sort",
                    isCorrect : false,
                    feedback : "Wrong Answer"
                },
                {
                    text : "Insertion Sort",
                    isCorrect : true,
                    feedback : "Correct Answer"
                }
            ],
            hints : "Ponder your thoughts about inplace and stable terms.",
            
        },
        {
            questionNumber : "Question 2",
            questionText: "Which of the trversal gives decreasing order of keys in a BST?",
            choice : [
                {
                    text : "Pre-Order",
                    isCorrect : true,
                    feedback : "Correct Answer"
                },
                {
                    text : "Post-Order",
                    isCorrect : false,
                    feedback : "Wrong Answer"
                },
                {
                    text : "In-Order",
                    isCorrect : false,
                    feedback : "Wrong Answer"
                }
            ],
            hints : "Know how are these orders are used in traversal.",
            
        }
    ]
};


loadQuestions();

function loadQuestions() {

    document.getElementById("loadingQuestionsPart").innerHTML = "<div> <h2> " + quiz.questions[0].questionNumber + 
    "</h2> <p>" + quiz.questions[0].questionText + "</p>" + "<button onclick = 'hintFunction(1)' class= 'btn btn-info'>Hint</button> " +
    "<p id='hint1'> </p>"
    + "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(1) id = 'Option1'>"
    +quiz.questions[0].choice[0].text+ "</input> </label> </div>"  +
     "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(2) id = 'Option2'>"
    +quiz.questions[0].choice[1].text+ "</input> </label> </div>"  + 
    "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(3) id = 'Option3'>"
    +quiz.questions[0].choice[2].text+ "</input> </label> </div> <p id = '1'> </p> <p id = '2'> </p> <p id = '3'> </p>" +
    "<div> <h2> " + quiz.questions[1].questionNumber + 
    "</h2> <p>" + quiz.questions[1].questionText + "</p>" + "<button onclick = 'hintFunction(2)' class= 'btn btn-info'>Hint</button> " +
    "<p id='hint2'> </p>"
    + "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(4) id = 'Option4'>"
    +quiz.questions[1].choice[0].text+ "</input> </label> </div>"  +
     "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(5) id = 'Option5'>"
    +quiz.questions[1].choice[1].text+ "</input> </label> </div>"  + 
    "<div class = 'radio'> <label> <input type='radio' name = 'optradio' onclick = Option(6) id = 'Option6'>"
    +quiz.questions[1].choice[2].text+ "</input> </label> </div> <p id = '4'> </p> <p id = '5'> </p> <p id = '6'> </p>"
}
function hintFunction(num) {

    switch (num) {
        case 1:
        document.getElementById("hint1").innerHTML = "<br>" + '<div id = "close1" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(1)">&times;</button>' +
        quiz.questions[0].hints + '</div>';
        break;
        case 2:
        document.getElementById("hint2").innerHTML = "<br>" + '<div id = "close2" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(2)">&times;</button>' +
        quiz.questions[1].hints + '</div>';
        break;
    }
}

function Option(num) {

    switch (num) {
        case 1:
        document.getElementById("1").innerHTML = '<div id = "close3" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(3)">&times;</button>' +
        quiz.questions[0].choice[0].feedback + '</div>';
        document.getElementById("Option1").disabled = "true";
        document.getElementById("Option2").disabled = "true";
        document.getElementById("Option3").disabled = "true";
        totalScore(quiz.questions[0].choice[0].isCorrect);
        break;
        case 2:
        document.getElementById("2").innerHTML = '<div id = "close4" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert"  onclick = "closeFunction(4)">&times;</button>' +
        quiz.questions[0].choice[1].feedback + '</div>';
        document.getElementById("Option1").disabled = "true";
        document.getElementById("Option2").disabled = "true";
        document.getElementById("Option3").disabled = "true";
        totalScore(quiz.questions[0].choice[1].isCorrect);
        break;
        case 3:
        document.getElementById("3").innerHTML = '<div id = "close5" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert"  onclick = "closeFunction(5)">&times;</button>' +
        quiz.questions[0].choice[2].feedback + '</div>';
        document.getElementById("Option1").disabled = "true";
        document.getElementById("Option2").disabled = "true";
        document.getElementById("Option3").disabled = "true";
        totalScore(quiz.questions[0].choice[2].isCorrect);
        break;
        case 4:
        document.getElementById("4").innerHTML = '<div id = "close6" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(6)">&times;</button>' +
        quiz.questions[1].choice[0].feedback + '</div>';
        document.getElementById("Option4").disabled = "true";
        document.getElementById("Option5").disabled = "true";
        document.getElementById("Option6").disabled = "true";
        totalScore(quiz.questions[1].choice[0].isCorrect);
        break;
        case 5:
        document.getElementById("5").innerHTML = '<div id = "close7" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(7)">&times;</button>' +
        quiz.questions[1].choice[1].feedback + '</div>';
        document.getElementById("Option4").disabled = "true";
        document.getElementById("Option5").disabled = "true";
        document.getElementById("Option6").disabled = "true";
        totalScore(quiz.questions[1].choice[1].isCorrect);
        break;
        case 6:
        document.getElementById("6").innerHTML = '<div id = "close8" class="alert alert-warning alert-dismissable">' +
        '<button type="button" class="close" data-dismiss="alert" onclick = "closeFunction(8)">&times;' +
        quiz.questions[1].choice[2].feedback + '</div>';
        document.getElementById("Option4").disabled = "true";
        document.getElementById("Option5").disabled = "true";
        document.getElementById("Option6").disabled = "true";
        totalScore(quiz.questions[1].choice[2].isCorrect);
        break;
    }
}

function closeFunction(num) {

    switch (num) {
        case 1:
        document.getElementById("close1").outerHTML = "";
        break;
        case 2:
        document.getElementById("close2").outerHTML = "";
        break;
        case 3:
        document.getElementById("close3").outerHTML = "";
        break;
        case 4:
        document.getElementById("close4").outerHTML = "";
        break;
        case 5:
        document.getElementById("close5").outerHTML = "";
        break;
        case 6:
        document.getElementById("close6").outerHTML = "";
        break;
        case 7:
        document.getElementById("close7").outerHTML = "";
        break;
        case 8:
        document.getElementById("close8").outerHTML = "";
        break;   
    }
}
function totalScore(num) {
    // console.log("reached");
    // console.log(num)
    if (num === true) {
        score += 1;
    }
}
function resetFunction() {
    location.reload();
}

function scoreDisplay() {
    document.getElementById("Score").innerHTML = "Score = " +score;
}<file_sep>import { Component, OnInit } from '@angular/core';
import { CartService } from '../cart.service';
import { Product } from '../card';
import {HttpClient, HttpHeaders} from '@angular/common/http';

@Component({
  selector: 'app-checkout',
  templateUrl: './checkout.component.html',
  styleUrls: ['./checkout.component.css']
})
export class CheckoutComponent implements OnInit {

  constructor(private cartService: CartService, private http: HttpClient) { }
  cartsArray: Product[] = [];
  totalQuantity: number = 0;
  country: string;
  address: string;
  city: string;
  state: string;
  post: string;

  ngOnInit() {
    this.getCart();
    this.calculateItems();
  }

  getCart() {
    this.cartsArray = this.cartService.getCart(); 
  }

  calculateItems() {
    for (var i = 0; i < this.cartsArray.length; i++) {
      this.totalQuantity += this.cartsArray[i].uRQ;
    }
  }

  checkuser() {
    var obj = {addr:[this.address, this.city, this.state, this.post, this.country]};
    this.http.post('http://127.0.0.1:3000/address', obj).subscribe(next => console.log(next));
  }
}
<file_sep>import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CardService } from '../card.service';
import { CartService } from '../cart.service';
import { UserService } from '../user.service';

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
  @Input() data: any;
  // flagForMessage: boolean = false;
  reviewRQ=false;
  userLogin=false;
  uname:string;
  comments:string;
  ratings: number;
  ids: any;
  constructor(private route: ActivatedRoute,
    private cardService: CardService,
    private cartService: CartService,
    private us: UserService) { }

  ngOnInit() {
    const id = this.route.snapshot.paramMap.get("id");
    this.ids = id;
    this.cardService.getCardsFromService().subscribe(productslist => this.data = productslist[id]);
  }

  addToCart(num: number) {
    alert("Product added to cart.")
    this.cartService.addToCartInService(num);
    if (this.us.isLoggedIn) {
      this.us.addtocart(num);
    }
    // this.flagForMessage = true;
    // window.setInterval(function() {
    //   // this will execute every 5 minutes => show the alert here
    //   var popup = document.getElementById("myPopup");
    //   popup.classList.toggle("show");
    // }, 3000);
    
  }
  updatereview() {
    var obj = {'uname': this.uname, 'comment': this.comments, 'rev': this.review, 'id':this.ids};
    this.cardService.updatereview(obj);
  }
  review(){
    this.reviewRQ=true;
  }
  reviewSubmit(){
    this.reviewRQ=false;
  }
}
<file_sep>var bodyparser = require('body-parser');
var userdb = require('mongoose');
var productdb = require('mongoose');


var urlencodedParser = bodyparser.urlencoded({extended:false});

userdb.Promise = global.Promise;
productdb.Promise = global.Promise;

userdb.connect('mongodb://Tulasi:<EMAIL>:31501/wpdata', {useNewUrlParser:true})

var userschema = new userdb.Schema({
    email: String,
    phone: Number,
    password: <PASSWORD>,
    address: [String],
    cartDetails: [Number],
    quantity: [Number],
    price: [Number]
});




var user = userdb.model('user', userschema);

// var itemOne = user({
//     email: "<EMAIL>",
//     phone: 1,
//     password: "<PASSWORD>",
//     address: ["j","j"],
//     cartDetails: [1,1],
//     quantity: [1,1],
//     price: [1,1]
// }).save(function(err) {
//     if (err) throw err;
//     console.log('User Saved');
// })
productdb.connect('mongodb://Tulasi:<EMAIL>:31501/wpdata', {useNewUrlParser:true});


var productschema = new productdb.Schema({
    
    prodId: Number,
    productTitle: String,
    productCategory: String,
    productDescription: [String],
    img: String,
    quantity: Number,
    price: Number,
    reviews: [{body: String, rating: Number, user: String}]
});
var products = productdb.model('products', productschema);
// var itemTwo = products({
//     prodId: 4,
//     productTitle: "red mi note 6 pro",
//     productCategory: "Mobile Phone",
//     productDescription: ["15.9 cm (6.26 inch) FHD+ Display with Resolution "],
//     img: "4.jpeg",
//     quantity:40,
//     price: 150,
//         reviews: []
// }).save(function(err) {
//     if (err) throw err;
//     console.log('Product Saved');
// })

module.exports = function(app) {
    app.get('/getusers', function(req,res){
        user.find({}, function(err, data){
            try {
                console.log(data);
                res.send(data);
            } catch (err) {

            }
        })
    });

    app.get('/getproducts', function(req,res){
        products.find({},function(err,data){
            try {
                // console.log(data);
                res.send(data);
            } catch(err) {

            }
        })
    });

       
app.post('/userlogin', function(req, res) {
    console.log(req.body);
    console.log(req.body.username);
    console.log(req.body.password);
    user.findOne({"email": req.body.username, "password": <PASSWORD>}, function(err, data) {
        try {
            console.log("inside try");
            console.log(data);
            if (data==null) {
                return res.send(false);
            } else {
                return res.send(true);
            } 
        } catch (err) {} })
});

    app.post('/adduser', function(req,res){
        console.log(req.body)
        user({
                email: req.body.username,
                phone: req.body.phn,
                password: <PASSWORD>,
                address: [],
                cartDetails: [],
                quantity: [],
                price: []
            }).save(function(err) {
                if (err) throw err;
                console.log('User Saved');
            })
    });

    // app.post("/addtocart",function(req,res){
    //     console.log(req.body);

    // })

    app.post('/review', function(req,res){
        console.log(req.body);
        productdb.findOneAndUpdate({'productid': req.body.prodId + 1}, {"$push": {reviews:[{body: req.body.comment, rating: req.body.rev, user: req.body.uname}]}},
        function(err) {
            if (err) throw err;
        });
    })
}<file_sep>var bodyparser = require('body-parser');
var userdb = require('mongoose');
var productdb = require('mongoose');


var urlencodedParser = bodyparser.urlencoded({extended:false});

userdb.Promise = global.Promise;
productdb.Promise = global.Promise;

userdb.connect('mongodb://Tulasi:<EMAIL>:31501/wpdata', {useNewUrlParser:true})

var userschema = new userdb.Schema({
    email: String,
    phone: Number,
    password: <PASSWORD>,
    address: [{address:String,city:String,state:String,postcode:String,country:String}],
    cartDetails: [Number],
    quantity: [Number],
    price: [Number]
});




var user = userdb.model('user', userschema);

// var itemOne = user({
//     email: "<EMAIL>",
//     phone: 1,
//     password: "<PASSWORD>",
//     address: ["j","j"],
//     cartDetails: [1,1],
//     quantity: [1,1],
//     price: [1,1]
// }).save(function(err) {
//     if (err) throw err;
//     console.log('User Saved');
// })
productdb.connect('mongodb://Tulasi:<EMAIL>:31501/wpdata', {useNewUrlParser:true});


var productschema = new productdb.Schema({
    
    prodId: Number,
    productTitle: String,
    productCategory: String,
    productDescription: [String],
    img: String,
    quantity: Number,
    price: Number,
    reviews: [{body: String, rating: Number, user: String}]
});
var products = productdb.model('products', productschema);
// var itemTwo = products({
//     prodId: 4,
//     productTitle: "red mi note 6 pro",
//     productCategory: "Mobile Phone",
//     productDescription: ["15.9 cm (6.26 inch) FHD+ Display with Resolution "],
//     img: "4.jpeg",
//     quantity:40,
//     price: 150,
//         reviews: []
// }).save(function(err) {
//     if (err) throw err;
//     console.log('Product Saved');
// })

module.exports = function(app) {
    app.get('/getusers', function(req,res){
        user.find({}, function(err, data){
            try {
                console.log(data);
                res.send(data);
            } catch (err) {

            }
        })
    });

    app.get('/getproducts', function(req,res){
        products.find({},function(err,data){
            try {
                // console.log(data);
                res.send(data);
            } catch(err) {

            }
        })
    });

       
app.post('/userlogin', function(req, res) {
    console.log(req.body);
    console.log(req.body.username);
    console.log(req.body.password);

    
    user.findOne({"email": req.body.username, "password": <PASSWORD>}, function(err, data) {
        try {
            console.log("inside try");
            console.log(data);
            if (data==null) {
                return res.send(false);
            } else {
                return res.send(true);
            } 
        } catch (err) {} })
});

    app.post('/adduser', function(req,res){
        console.log(req.body)
        user({
                email: req.body.username,
                phone: req.body.phn,
                password: <PASSWORD>,
                address: [],
                cartDetails: [],
                quantity: [],
                price: []
            }).save(function(err) {
                if (err) throw err;
                console.log('User Saved');
            })
    });
    var jsonparser = bodyparser.json();
    app.put('/putRevs', jsonparser,function(req, res){
        console.log("In revs")
        console.log(req.body);
        var val = {body:req.body.body, rating:req.body.rating, user:req.body.user}
        products.findOneAndUpdate({prodId:req.body.id},{$push:{reviews:val}}, (err, docs)=>{
          if(err) console.log(err);
          else console.log("pushed");  
        })
    })
    // var 
    app.put('/saveAdd',jsonparser,function(req,res){
        var add={address:req.body.address,city:req.body.city,state:req.body.state,postcode:req.body.postcode,country:req.body.country};
        user.findOneAndUpdate({email:req.body.email},{$push:{address:add}},{new:true},(err,docs)=>{
            if(err) console.log(err);
            else console.log(docs);
        })
    })
    app.put('/update',jsonparser,function(req,res){
        var val=0;
        products.find({prodId:req.body.prodId}, function(err,docs){
            val=docs[0].quantity;
            val=val-req.body.uRQ;
            if(err) console.log(err);
            else{
                products.findOneAndUpdate({prodId:req.body.prodId},{$set:{quantity:val}},function(err,doc){
                    if(err) throw err;
                    console.log(docs);
                })
            }
        })
    });

}<file_sep>import { Injectable } from '@angular/core';
import { Product } from './card';
import { CARDS } from './mock-cards';

@Injectable({
  providedIn: 'root'
})
export class CartService {

  constructor() { }
  cartArray: Product[] = [];
  
  addToCartInService(num: number) {
    for (var i = 0; i < this.cartArray.length; i++) {
      if (num === this.cartArray[i].prodId) {
        this.cartArray[i].uRQ += 1;
        return; 
      }
    }
    this.cartArray.push(CARDS[num - 1]);
  }

  getCart() {
    return this.cartArray;
  }
}
