<file_sep>
// function fun(str,num1) {
    
   
//     for(var i = 1;i<=num1;i++){
//         console.log(str);
//     }
// }

// fun("wasif",4)


function average(scores){
    let sum = 0;
     let avg =0;
    scores.forEach(function(score){
        sum += score;
        
    });
    
        avg = sum/scores.length
        return  Math.round(avg);
    }

 
var scores = [10, 20, 30, 40, 50, 60];
console.log(average(scores));<file_sep>var mongoose = require("mongoose");

mongoose.connect("mongodb://localhost:27017/blog_demo_2", {useNewUrlParser:true});

//POST schema

var postSchema = new mongoose.Schema({
    title: String,
    content: String
});

var Post = mongoose.model("Post", postSchema);

// USER schema

var userSchema = new mongoose.Schema({
    name: String,
    email: String,
    posts: [
            {
                 type: mongoose.Schema.Types.ObjectId,   
                 ref: "Post"
            }
         ]
});

var User = mongoose.model("User", postSchema);
//-------------------------------
User.create({name: "bob", 
            email:"<EMAIL>"});

Post.create( {title:"how to cook a meal pt 2",
                Content:"just follow the recipe"}, function(err, post){
                User.findOne({ name:"bob"}, function(err, foundUser){
                    
                    if(err){
                        console.log(err);
                    } else {
                        foundUser.posts.push(post._id);
                        foundUser.save(function(err, data){
                            if (err){
                                console.log(err);
                            } else {
                                console.log(data);
                            }
                        });
                    }
                });
                });
                
    User.findOne({name: "bob"}).populate("posts").exec(function (err,user){
        if (err){
            console.log(err);
        } else {
            console.log(user);
        }
    });
                <file_sep># C9-backup
<file_sep>var express = require("express")
var app = express();

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 sound = "";
  
    if (animal === "dog"){
        sound = "woof woof";
            }
    else if (req.params.animal === "whale"){
          sound = "sonic";
            }
    else if (req.params.animal === "horse"){
         sound = "neigh";
            }
    else if (req.params.animal === "cat"){
          sound = "Meow";
            }
    else if (req.params.animal === "arshia"){
          sound = "bhaukna";
            }
    
    res.send("the animal is " + animal +" with the sound of "+ sound);
    
});

app.get("/repeat/:message/:times", function (req,res) {
    var message = req.params.message;
    var times = Number(req.params.times);
    var result = "";
    
    for( var i = 0; i <= times; i++){
        result += message + " ";
        }
    res.send(result);
});

app.get("/*", function (req,res) {
    res.send("you have entered a wrong URL");
});

app.listen(process.env.PORT, process.env.IP, function(){
    
    console.log("the server has started");

});<file_sep>var mongoose =require("mongoose");

mongoose.connect("mongodb://localhost:27017/blog_demo", {useNewUrlParser:true});

//POST schema

var postSchema = new mongoose.Schema({
    title: String,
    content: String,
});

var Post = mongoose.model("Post", postSchema);

//USER schema

var userSchema = new mongoose.Schema({
    name: String,
    email: String,
    posts: [postSchema]
});

var User = mongoose.model("User", userSchema);

//=--------------------------------------=

// var newUser = new User({
//     name: "Hermione",
//     email: "<EMAIL>",
 
// });

//  newUser.posts.push( {
//         title:"things that i hate",
//         content: "voldemort. voldemort. voldemort."
//     });
    
// newUser.save(function (err, user){
//     if(err){
//         console.log(err);
//     } else {
//         console.log(user);
//     }
// });

User.findOne({name:"Hermione"}, function(err, user){
    if (err) {
        console.log(err);
    } else {
        user.posts.push({
            title:"to do list",
            content: "go to potions class"
        });
    }
    
    user.save(function(err, user){
        if (err){
            console.log(err)
        } else {
            console.log(user)
        }
    });
});

// var newPost = new Post({
//   title:"how to be succeful",
//   content: "true determination and never give up, thats all!! "
// });

// newPost.save(function(err, post){
//      if(err){
//         console.log(err);
//     } else {
//         console.log(post);
//     }
// });<file_sep>var faker = require("faker");


var randomName = faker.name.findName(); // <NAME>
var randomEmail = faker.internet.email(); // <EMAIL>
var randomCard = faker.helpers.createCard(); // random cont
var randomprod = faker.commerce.product();
var randomprice = faker.helpers.price();

// console.log(randomName);

console.log("=================================");
console.log("             welcome             ");
console.log("=================================");


for(var i = 1; i <= 10 ; i++);
{
console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));


// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
// console.log(faker.fake("{{commerce.product}} - ${{commerce.price}}"));
};

    















<file_sep>
function average(scores){
    var sum, avg = 0;
    
    scores.forEach(function(score){
        sum += score;
        
    });
    
        avg = sum/scores.length;
        return  Math.round(avg);
    }

 
var scores = [10, 20, 30, 40, 50, 60];
console.log(average(scores));<file_sep>const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/cat_app");

const catSchema = new mongoose.Schema({
   name: String,
   age: Number,
   temperament: String
});

let Cat = mongoose.model("Cat",catSchema);

var george = new Cat({
  name: "<NAME>",
  age: "9",
  temperament: "grouchy"
});

george.save(function(err, cat){
    if(err){
        console.log("we ran into an error");
    }
    else{
        console.log("the saved cat is");
        console.log(cat);
    }
    
});

Cat.find({},function(err, cats){
    if(err){
    console.log("we got an ERROR!")
    }
    else{
        console.log("there are no errors!");
        console.log(cats);
    }
    
});

Cat.create({
    name:"lolo",
    age:"12",
    temperament:"susthad"
    
},function(err, cats){
    if(err){
    console.log("we got an ERROR!")
    }
    else{
        console.log("there are no errors!");
        console.log(cats);
    }
    
});