Project 1

Previous Next

Source Code
// Project 1

console.log('** Birthday Party **');

let party = {
    guestsLimit: 100,
    host: 'Saad',
    birthDayboy: "Kumail",
    date: "23 August, 2015",
    guests: [
        {
            name: 'Amir',
            age: 12,
            gift: true,
            gifts: ['PS4', 'xbox', 'cycle']
        },
        {
            name: 'Zia',
            age: 15,
            gift: false,
            gifts: []
        },
        {
            name: 'Khalid',
            age: 22,
            gift: true,
            gifts: ['bike']
          }
    ]
}


let addNewGuest = document.getElementById('addNewGuest').onclick = function () {
    addGuest()    
}

function addGuest () {

let howManyGuest;

do {

     howManyGuest = prompt('How many guests?');

    if(isNaN(howManyGuest)) {
        console.log('Please write guest number in integer');
    }
    
}while(isNaN(howManyGuest)) {

    for(let guest = 1; guest <= howManyGuest; guest++){

        const guestName = prompt('Guest ' + guest + ' name?');

        let guestAge;

        do {
            guestAge = prompt('Guest ' + guest + ' age?');

            if(isNaN(guestAge)) {
                console.log('Bhai please age 123 main leko');
            }
            
        }while(isNaN(guestAge)){

            let isGift = prompt('Kuch laye hu? I mean giftsssssss');

            if(isGift == 'yes') {

                isGift = true;

                let howManyGifts;
                do {
                    howManyGifts = prompt('How many gifts');
        
                    if(isNaN(howManyGifts)) {
                        console.log('Bhai please 123 main leko');
                    }
                    
                }while(isNaN(howManyGifts)) {

                    let newGifts = [];

                    for(let gift = 1; gift <= howManyGifts; gift++) {
                        const newGift = prompt('Please write gift ' + gift + ' name?');
                        newGifts.push(newGift)
                    }
            
                    const newGuest = {
                        name: guestName,
                        age: guestAge,
                        gift: isGift,
                        gifts: newGifts
                    }

                    party.guests.push(newGuest)

                }
            }else{
                isGift = false

                let newGifts = [];

                const newGuest = {
                    name: guestName,
                    age: guestAge,
                    gift: isGift,
                    gifts: newGifts
                }

                party.guests.push(newGuest)
            }
            
            

        }

         
    
    }

}

console.log(party)

}

Technologies


Features
Type Learn with Aamir
Date Created September 21, 2021
Last Updated 11, Feb 2021
Licence MIT
envelope
Subscribe to our newsletter to receive weekly design freebies!

We want your email to send the free themes, templates, and beautiful UI components every week. you will be the first to hear about new uploads NO SPAM.

4 x 3 =
Answer to the quesiton to submit