Celebrate Earth Day with Print: "Happy Earth Day"
Happy Earth Day! Today, we celebrate our beautiful planet, and one way to participate is by spreading awareness through coding. Let's explore how to use the print function in several popular programming languages to display "Happy Earth Day" in your console.
Whether you're a seasoned developer or just starting your coding journey, understanding how to print text to the console is a fundamental skill. So let's dive into the world of programming to celebrate our planet.
JavaScript
JavaScript is a versatile language used primarily for web development. Here's how you can print "Happy Earth Day" to the console using JavaScript:
console.log('Happy Earth Day');
Using Console.log with an Emoji
To make it more festive, you can use an Earth emoji right in your console. Here's how to do it:
console.log('Happy Earth Day π');
Printing in a Styled Format
You can also print your message in a styled format using CSS. This won't change the console appearance but will make your "Happy Earth Day" message noticeable:
console.log('%cHappy Earth Day', 'color: green; font-weight: bold;');
Python
Python is another popular language used in various applications, including data analysis and scientific computing.
Using the print() Function
Python has a built-in function called `print()`. Here's how you can use it to print "Happy Earth Day" to the console:
print("Happy Earth Day")
Printing with an Emoji
You can also include an emoji in your message, just like in JavaScript:
print("Happy Earth Day π")
Java
Java is a widely-used language for building business applications, games, and Android apps.
System.out.println()
Java uses `System.out.println()` to print text to the console. Here's how to use it:
System.out.println("Happy Earth Day");
Printing with an Emoji
In Java, you can use the same approach as in Python and JavaScript to include an emoji in your message:
System.out.println("Happy Earth Day π");
Don't forget, every act of kindness to our planet makes a difference. So keep coding, and happy Earth Day! π