1 / 7

Session ObjectivesU2 #S10

Session ObjectivesU2 #S10 . Key Words. Local Variable. Global Variable. Constant. Modularisation. Initialise. Concatenate. Constants and Variables. Many programs contain values that do not change whilst the program is running, for example Pi.

ona
Download Presentation

Session ObjectivesU2 #S10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session ObjectivesU2#S10

  2. Key Words Local Variable Global Variable Constant Modularisation Initialise Concatenate

  3. 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. 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 variablesare 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. 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. 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. Key Words Local Variable Global Variable Constant Modularisation Initialise Concatenate

More Related