JSFiddle - React, Tailwind, and code Playground

by 1eddy87

JavaScript

const getFruit = async (name) => {
    const fruits = {
        "peach": "πŸ‘",
        "strawberry": "πŸ“",
        "pineapple": "🍍"
    }
    
	/* console.log(fruits['peach']) */
    return fruits[name];
}

/* let result = getFruit("peach");
console.log('result', result);
*/
 
/* getFruit("pineapple").then(console.log); */
 
// Promise
/*
const makeSmoothie = () => {
    let v = [];
    return getFruit("peach")
    .then(a => {
        v.push(a);
        return getFruit("pineapple").then(b => {
            v.push(b);
            console.log(v);
        });
    });
    
    // test
    let a = new Promise((resolve, reject) => {
        let error = false;
        
        if (!error) {
            return resolve(getFruit("peach"));
        } else {
            return reject('Error: no fruit for you!');
        }
    });
    
    a.then(console.log).catch(console.log);
}

makeSmoothie();
*/

// Promise.all();

const makeSmoothie = () => {
    let a = getFruit("peach");
    let b = getFruit("pineapple");
    
    Promise.all([a, b]).then(console.log);
}

makeSmoothie();