skip to content
tlam://snippet
cd ..

A sunny day

This is what ChatGPT told me a sunny day was in JS... "Here's a fun JavaScript class representing a sunny day, complete with methods to shine, warm up, cool down, change mood based on cloudiness, and even experience a beautiful sunset. Enjoy the digital sunshine! 🌞😎"

a_sunny_day.js Β· 48 lines Β· javascript
class SunnyDay {    constructor(temperature = 25, cloudiness = 0, mood = "cheerful") {        this.temperature = temperature;        this.cloudiness = cloudiness; // 0 means no clouds, 100 means storm incoming!        this.mood = mood;        this.brightness = 100 - this.cloudiness;    }    shine() {        if (this.cloudiness > 80) {            return "The sun is trying its best, but those clouds are really in the way...";        }        return `The sun is shining brightly with a brightness level of ${this.brightness}!`;    }    warmUp() {        this.temperature += 5;        return `The temperature rises to ${this.temperature}Β°C. Perfect weather for ice cream!`;    }    coolDown() {        this.temperature -= 5;        return `The temperature drops to ${this.temperature}Β°C. Maybe grab a light jacket?`;    }    getMood() {        if (this.cloudiness > 70) {            this.mood = "gloomy";        } else if (this.temperature > 30) {            this.mood = "blazing";        } else {            this.mood = "cheerful";        }        return `The day feels ${this.mood} today.`;    }    sunset() {        return "The sun slowly dips below the horizon, painting the sky in breathtaking colors.";    }}// Example usage:const today = new SunnyDay(28, 10);console.log(today.shine());console.log(today.warmUp());console.log(today.getMood());console.log(today.sunset());

replies (0)

login to reply.

// no replies yet