Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

Jan 30, 2025
b23779b · Jan 30, 2025

History

History
31 lines (21 loc) · 679 Bytes

File metadata and controls

31 lines (21 loc) · 679 Bytes

Still a promise

Make the 3 horses run then show their times

class Horse {
    constructor(name) {
        this.name = name;
    }

    async run() {
        const time = Math.random() * 30 + 10; // 10 to 40 seconds
        
        await new Promise(resolve => setTimeout(resolve, time * 1000 / 20)); // 20x. We don't want to wait realistic times, do we?

        const result = `${time.toFixed(2)} seconds for ${this.name}!!! `; // name, seconds.hundreths
        console.log(result);
        return result;
    }
}

const babieca = new Horse('Babieca');
const rocinante = new Horse('Rocinante');
const bucephalus = new Horse('Bucephalus');

// Your code...
//