0% found this document useful (0 votes)
117 views

CoP004 Javascript

ORB EDUCATION QUALITY TEACHING RESOURCES www.orbedu.com Worksheets, Lesson Plans, PowerPoints and Interactive Resources for School, Home and Distance Learning ORB Education provides a range of quality, professional teacher resources, including printable worksheets, lesson plans, PowerPoints and interactive packages. Materials are originally teacher-created (and therefore packed with quality, engaging, differentiated tasks) then polished up by our team of editors and experts. Our individual digital resource files can be displayed on an interactive whiteboard, printed, photocopied, shared on your network, placed on your school intranet, LMS/VLE and even emailed to students during distance learning. Products can be downloaded immediately.

Uploaded by

ORBeducation
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

CoP004 Javascript

ORB EDUCATION QUALITY TEACHING RESOURCES www.orbedu.com Worksheets, Lesson Plans, PowerPoints and Interactive Resources for School, Home and Distance Learning ORB Education provides a range of quality, professional teacher resources, including printable worksheets, lesson plans, PowerPoints and interactive packages. Materials are originally teacher-created (and therefore packed with quality, engaging, differentiated tasks) then polished up by our team of editors and experts. Our individual digital resource files can be displayed on an interactive whiteboard, printed, photocopied, shared on your network, placed on your school intranet, LMS/VLE and even emailed to students during distance learning. Products can be downloaded immediately.

Uploaded by

ORBeducation
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Section C.

Variables

Variables are a way of storing information. The variables x and y are often used in algebra, assigning a value to each e.g. x = 2 and y =
4. We can also use variables in JavaScript, but you must declare them first using the term ‘var’. Declaring a variable is a way of saying
“a variable exists and this is its name” e.g.

var valueX = 2
var valueY = 4
var valueZ

valueX is the name of a variable. It has been given the value 2.


valueY is the name of a variable. It has been given the value 4.
valueZ is the name of a variable. It has not yet been given a value.

You can then use these variables in calculations.

Task 1
Using the fact that valueX = 2 and valueY = 4, write down the value of the variable ‘valueZ’ in each case below:

a. valueZ = valueX + 3
b. valueZ = valueX * 2 (* is the symbol used for multiply)
c. valueZ = valueX / 2 (* is the symbol used for divide)
d. valueZ = valueX + valueY
e. valueZ = (valueX – valueY) * 7

Some rules concerning variables

1. Variables should be declared before use, using the term ‘var’


2. Variables must start with a letter or an underscore (e.g. FirstName rather than 1stName)
3. Variables can only contain letters, numbers and the underscore (e.g. Address_1).
4. Variables are case sensitive (valueZ is not the same as valuez)
5. Life will be easier if you choose names that mean something (e.g. ‘PeopleCount’ rather than ‘x7’)

Task 2
Add the following code to a new page and look at it in ‘Preview’ (remember that the JavaScript is placed between the </title> and
</head> tags.

<script LANGUAGE="JavaScript">
<!-- A semi-colon (;) is used at the end of
var valueX = 2; each statement
var valueY = 4;
var valueZ = valueX + valueY;
alert(valueZ);
//-->
</script>

Task 3
Adjust the script so that it calculates and displays each of the following sums (there are many ways of achieving the correct results).
Write down the answers.

a. 2345 + 432 __________________

b. 25 * 378 __________________

c. 3578 / 72 __________________

d. (34 * 23) + 97 __________________

ORB Education Quality Teaching Resources


 ORB Education Visit http://www.orbedu.com for the full, editable versions with solutions. CoP004 - JavaScript

You might also like