Page 134 - KEC Khaitan C5 Flipbook
P. 134
WORKING WITH VARIABLES AND CHAPTER
CONDITIONAL LOGIC C3
learning outcomes
understand the concept and purpose of variables in programming.
declare, update, and use variables for calculations and user input.
apply arithmetic and Boolean operators in programs.
use if and if-else statements for decision-making.
create interactive apps using variables and conditions.
INTRODUCTION TO VARIABLES AND THEIR FUNCTIONS
In programming, variables are used to store and manipulate data. Think of a variable as
a labelled box where you can keep information that can change as the program runs. In
Code.org's App Lab, variables allow us to manage user input, perform calculations, and
control program behaviour dynamically.
DECLARING VARIABLES IN APP LAB
To create a variable in App Lab, we use the var keyword:
score is a numerical variable storing a value of 0.
playerName is a string variable that stores text ("Alex").
Example: to declare and update variable.
var score = 0;
var playerName = "Aman";
Once declared, variables can be updated throughout the program:
score = score + 1;
playerName = "Simran";
FUNCTIONS OF VARIABLES
Variables help make programs more interactive and dynamic. For example:
132 Premium Edition-V

