Skip to main content

Posts

Showing posts with the label conditional keywords

JavaScript Project Study:Four Steps To Build A Simple Guessing Number Game

So far I have learned some basic JavaScript language such as conditional keywords, logical operators, and built-in methods. Today, we will build a simple guessing number game by applying those JS basic language. Basically, the game is ask user to guess a number, if the number is match to the secret number, they win the game. If not, they will have to try again. Step One: Create a simple HTML page and Link to the JS file I start to build a simple HTML page and give a title "Guessing Game" for it. Then, I create a separate JS file named "game.js", and link to the HTML page. Step Two: Create Secret Number and Prompt Question In the JS file, I start to create a secretNumber which is 6. Six is a lucky number in China which means everything goes well as you wish. Then I ask a prompt question:"Guess A Number", so user will enter a number. Step Three: If users enter the right number, they will receive a message It is conditional, so I u...

JavaScript Basic: Three Conditional Keywords You Should Know

JavaScript conditionals is how you add logic to your programming and help you make decisions with code. For example, when we shop online and ready to pay our items, we will enter our credit card number, if our information is correct, it will match the code, and we will receive a confirmation message. If our credit card information is wrong, the code will send us an error message. There are three JS conditional keywords: If, Else If, and Else. How do we use those conditional keywords in JavaScript? If For example, if the website wants to send an message about your age is younger than 18, you can't enter the bar. if (age < 18) { console.log("Sorry, you are not old enough to enter the venue."); } Else If If your age is older than 18 but younger than 21, you can enter the bar but can not drink. else if (age < 21) { console.log("You can enter, but can not drink."); } Else If your age is older than 21, feel free to drink. ...