Skip to main content

Posts

Showing posts with the label prompt

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: Prompt & Console.log Exercise

Today the course assigned a simple JavaScript exercise: Here is my steps: Step One: Create a HTML page and link to the JavaScript File I create a simple HTML page and give a title "JS Stalker Exercise". Then, I link the HTML page to a new JS file named "stalker.js". Step Two: Enter variable data in the JS file In the JS file, I start to write three prompt messages which are asking for user's first name, last name and age. In order to print out user's full name and age in separate sentences, I set two console.log message. The only thing we need to pay attention is the spacing between each word.  The print sentence has one small space between each word : Your full name is X X. Therefore, in the console.log, we need to set the right space for each word. Step Three: Test the result When I open the page, it asks me three pop up questions in orders: After I answer each questions, I can see the print sentences in...

JavaScript Basic: Three Useful Built-In Methods To Act Your Site

In the last post, I shared five primitive data types. Even though I could write some basic variables and do some math in the console, I don't see any action from the website.  How to let website take action? We will need to know three built-in methods: Alert It pops up a message to the user, and it alerts the user. Console.log What console.log will do is print something to the JavaScript console. Prompt Prompt is very useful for us because it lets us get input from a user. The second part of prompt is that we can store it in a variable. Now I am going to apply those three built-in methods in HTML, so you can see how they work. Firstly, I create a simple HTML page, and I only add the title. Then I add a <script> tag and link to a separate file named "script.js". I want my site to pop up a message when you open it. In the "script. js" file, I name my variable as "userName", and it equal to prompt("What is ...