6
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 myvariable myvariable=”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”).

Variables

Embed Size (px)

Citation preview

Page 1: Variables

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”).

Page 2: Variables

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

Page 3: Variables

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.

Page 4: Variables

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);

Page 5: Variables

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.

Page 6: Variables

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.