Read more here
Today you are learning:
- some basic features of JavaScript
- how to create a variables, conditionals and alerts
- Mash it all up to create you own program
JavaScript is a an object-oriented computer programming language commonly used to create interactive effects within web browsers. You will have used it when every you have interacted with a website. These examples and activities will introduce you to introduce you to some basic features and code. Most JS runs automatically when a web page loads, to stop this some of the code is commented out with ###delete the ### to run the code###. Remove the ### to run the code.
Part 1: Basic Writing
Part 1: Basic Writing
- In the program below you will see that the code writes the sentence to the webpage, this uses the document.write() code to display the text.
- Change the code so that it displays "I have written text to a website"
- Can you add two lines of text to the display?
Part 2: Adding a Button
- Run the code below - what does it do?
- Change the text on the button to display "Move the mouse and click me"
- Can you correct the error so the message is displayed?
Part 3: Alerts
- Run the code below - what does it do?
- Change the message and the button text
- Can you use this code to edit and correct the code on Part 2?
- Add another button to the code below
Part 4: Variables
Variables can be create using the code var and then the name of the variable
Variables can be create using the code var and then the name of the variable
- Remember what a variable is?
- Look at the program below, what does it do? Run the code and check
- Create your own program below
Part 5: So Many Errors
- The code below contains 5 errors that stop the program from working. Each error is indicated by the 'error' hint. Can you edit the code to correct the 5 errors to make it work?
Part 5: Conditions:
Conditions are used to do something or something else depending on the condition met. If this then that etc, if greater than 10, print something.
Conditions are used to do something or something else depending on the condition met. If this then that etc, if greater than 10, print something.
- Edit the code below so that the password you enter is accepted and it displays the following message, "Welcome you may enter".
- Change the password to one of your choice.
Part 6: Drop Down Menus
- Below is a simple example of a drop-down program
- Run the program, see what is does.
- Add two more options of your choice to the drop down list
Part 7: The Area of a Triangle: putting it altogether
- The program below calculates the area of a triangle - run it.
- Can you make a program to calculate the area of a square?
- Adapt the program to calculate the area of a circle?