/*
let p = new Promise((resolve, reject) => {
    let a = 1 + 1 + 1
    if (a == 2){
        resolve("Success")
    } else {
        reject("failed")
    }
})

p
.then((message) =>{
    console.log("This is in the then" + message)
}).catch((message) => {
    console.log("in the catch" + message)
})
*/

const userLeft = false;
const userWatchingCatMeme = false;

function watchTutorialCallback(callback, errorCallback){
    if (userLeft){
        errorCallback({
            name: "User Left",
            message: ":("
        })
    } else if(userWatchingCatMeme) {
        errorCallback({
            name: "User Watching Cat Meme",
            message: "Cats are cute"
        })
    } else {
        callback("Thumbs up and subscribe")
    }
}



watchTutorialCallback(function (message) {
    console.log(`Success: ${message}`)
}, (error) => {
    console.log(`${error.name}: ${error.message}`)
}
)

function watchTutorialPromise(){
    return new Promise((resolve, reject) => {
        if (userLeft){
            reject({
                name: "User Left",
                message: ":("
            })
        } else if(userWatchingCatMeme) {
            reject({
                name: "User Watching Cat Meme",
                message: "Cats are cute"
            })
        } else {
            resolve("Thumbs up and subscribe")
        }
    })
}

watchTutorialPromise().then((message) => {
    console.log(`Success: ${message}`)  
}).catch((error) => {
    console.log(`${error.name}: ${error.message}`)
})


let prom1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve("ASD")
    }, 2000)
})

let prom2 = new Promise((resolve, reject) => {
    resolve("ASD2")
})

let prom3 = new Promise((resolve, reject) => {
    resolve("ASD3")
})

Promise.all(
    [
        prom1,
        prom2,
        prom3
    ]
).then((messages) => {
    console.log(messages)
})

