Upload
max-friel
View
4.150
Download
0
Embed Size (px)
Citation preview
Variables in coding
A variable allows us to store information/value which we can use for programming.
*create a .Js file (new=>file=>javascript) on dreamweaver and enter the following-
Var myvariablemyvariable=”hello world”;
alert (myvariable);
Save as variable.js then open a new html file and link them(new=>file=> html then <script src=”variable.js”).
Data types we use in variables
There are 3 types of data we use in javascript, string,numbers and boolean.
Var variable=”hello world”; //string
var ten=10; //used for equations
var isboolean; true //used for true/false conditions
Working with numbers
Open a new .js file and enter the following=>
var sum = 4 + 5,
difference= 4-5,
division= 20/ 4;
save as math.js and then use alert to produce a message for each variable.
If we put in some words with “”, the program will produce the text. We dont need to use “” for numbers.
var sum = 4 + 5,
difference="hello + goodbye",
division= 20/ 4;
alert(difference);
Activity 1
Write a program to produce the number 50.
Activity 2 Write a program that would show an equation
followed by it's answer. *hint – use 2 alerts.
Activity 1
Write a program to produce the number 50.
Activity 2 Write a program that would show an equation
followed by it's answer. *hint – use 2 alerts.