Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants.

Similar presentations


Presentation on theme: "A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants."— Presentation transcript:

1 A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants are used and how variables are intialised COULD create a program that concatenates string variables Create a program which allows a user to input name, date of birth and outputs the result + star sign

2 A Level Computing#BristolMet Key Words

3 A Level Computing#BristolMet Constants and Variables Many programs contain values that do not change whilst the program is running, for example Pi. Novice programmers may use ‘literals’ in their code for these values i.e circumference = 3.14159 * diameter Best Practice – it is better to declare the value of Pi as a constant first i.e CONSTANT Pi = 3.14159 VARIABLE diameter Circumference = Pi * diameter TASK: Write and test this program in Javascript EXT: Write and test a program to calculate the area of a circle in Javacsript.

4 A Level Computing#BristolMet Constants and Variables For the extension you will have had to declare a variable to store the value of the radius. Variables can be either Local or Global Local variables are declared and used inside a subroutine or ‘module’ and can only be used in that section code. Global variables are declared at the beginning of the program and be accessed throughout the code, including any subroutines. TASK: Although it is not modular Discuss what type of variable you have used in your Javascript programs TASK 2: Write and answer Q1 a and b p.118 Hodder

5 A Level Computing#BristolMet Initialising Variables Some programs initialise when they are declared which means they are given a starting value: Usually integers are set 0, Booleans set to FALSE and strings are set to empty. Consider this algorithm for adding any 5 numbers and outputting the total BEGIN For i = 1 to 5 INPUT Number Total = Total + Number NEXT i OUTPUT Total END This will only work if the value of Total is set to 0 to begin with. If the system does this automatically then it will work otherwise Total will need to be initialised by inserting the line Total = 0 at the declaration or assignment of the variable TASK: Attempt to create this program in Javascript and Python. Compare the 2 languages

6 A Level Computing#BristolMet String Manipulation:Concatenate Many programs need to deal with text therefore functions and operations are provided that manipulate strings. Concatenate - this means to join 2 strings together to make one. The + operator is usually used for this operation e.g FullName = FirstName + Surname FullName = FirstName +“ “ +Surname would be a better way to write this, why? TASK: Design and create a programme in Javascript which allows a user to input their name and birth date and output the result in one line. EXT: Extend the program to also output the users star sign TASK 2: Now attempt part c of Q1 p.118

7 A Level Computing#BristolMet Key Words


Download ppt "A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants."

Similar presentations


Ads by Google