Java(script) can make Java?!
Did you know that computers can go through all the steps to make coffee for us?
Okay, so that's not enirely true. However! JavaScript is a language in coding that can create an object that reflects it's real world counterpart and behaves with the same traits. This, by definition, is what an object is in JavaScript. This however is not the focus of this blog. Instead, I want to turn our attention towards a function in JavaScript known as the If/Else Statement. So what is an function in JavaScript? I'm so glad you didn't ask so I can share this information to you. Pro-bono!
JavaScript, as a language, behaves differently than other lines of code that use HTML or CSS as its primary language. HTML focuses on a markup language that structures the content shown on a web page, while CSS acts as the style sheet used to describe the presentation of HTML elements and overall aesthetics. JavaScript, in comparison to both of those previous languages, is a dynamic language that adds interactivity and responsive behavior to web pages. It enables developers to create lines of code that respond to the actions of the user interacting with the webpage. A function is a reusable block of code designed to perform a designated task or calculate a value. Our if statement is one of these very functions.
An If statement is a conditional statment that allows us to execute a block of code only if a specific condition is true. It provides us with a way to control the flow of a program based on whether a particular expression is evaluated as true or false, which is a Boolean statement. Here is an example of an If/Else Statement:
// These of the designated variables var isPluggedIn = true; var hasWater = true; var hasCoffeeGrounds = true; // Check if the conditions are met to make coffee if (isPluggedIn && hasWater && hasCoffeeGrounds) { console.log('Making coffee...'); console.log('Coffee is ready! Enjoy!'); } else { console.log('Cannot make coffee. Please ensure the coffee pot is plugged in, and there is water and coffee grounds.'); }