CodeKilla Programming Lab

Master programming fundamentals through interactive examples, workflow diagrams, and live code execution.

Introduction to Programming

Understanding the fundamentals of how computers execute instructions

What is Programming?

Programming is the process of creating instructions that a computer can execute to perform specific tasks. It's like writing a recipe, but for computers!

Program Execution Workflow

1 Write Code: Developer creates source code in a programming language
โ†“
2 Compilation/Interpretation: Code is translated to machine-readable format
โ†“
3 Execution: CPU processes the instructions
โ†“
4 Output: Program produces results (display, file, network, etc.)

Key Programming Paradigms

Procedural
๐Ÿ“‹

Step-by-step instructions

Object-Oriented
๐ŸŽฏ

Objects & classes

Functional
โšก

Pure functions

Variables

Containers for storing data values that can change during program execution

Understanding Variables

A variable is like a labeled box that can hold different values. You can store data, retrieve it, and change it.

Variable Lifecycle

1 Declaration: let name; - Reserve memory
โ†“
2 Initialization: name = "Ashok"; - Assign initial value
โ†“
3 Usage: console.log(name); - Read value
โ†“
4 Modification: name = "Ashok"; - Change value

Interactive Variable Demo

Declare and initialize a variable to see it in action!

Try It Yourself - Variables

JavaScript

Constants

Immutable values that cannot be changed after initialization

Constants vs Variables

Feature Variable (let) Constant (const)
Can be reassigned? โœ“ Yes โœ— No
Must initialize? โœ— Optional โœ“ Required
Use case Values that change Values that stay fixed

Try It Yourself - Constants

JavaScript

Data Types

Different kinds of data that can be stored and manipulated

Primitive Data Types

Number
42

Integers & decimals

String
"Hello"

Text data

Boolean
true

True or false

Undefined
undefined

No value assigned

Null
null

Intentionally empty

Try It Yourself - Data Types

JavaScript

Operators

Symbols that perform operations on values and variables

Operator Types

Type Operators Example Result
Arithmetic + - * / % 10 + 5 15
Comparison == != < > <= >= 10 > 5 true
Logical && || ! true && false false
Assignment = += -= *= /= x += 5 x = x + 5

Interactive Calculator

Result will appear here

Try It Yourself - Operators

JavaScript

Comments

Documentation within code that is ignored by the computer

Why Use Comments?

Comments help explain code to other developers (and your future self!):

  • Explain complex logic
  • Document function parameters and return values
  • Leave TODOs and notes
  • Temporarily disable code during debugging

Try It Yourself - Comments

JavaScript

If Statements

Making decisions in code based on conditions

Conditional Logic Workflow

If-Else Decision Flow

1 Condition Check: Evaluate boolean expression
โ†“
2 True Branch: Execute code in if block
OR
3 False Branch: Execute code in else block
โ†“
4 Continue: Resume normal execution

Interactive Decision Demo

Enter an age to check voting eligibility

Try It Yourself - If Statements

JavaScript

Loops

Repeating code execution multiple times

Loop Types

For Loop
๐Ÿ”„

Fixed iterations

While Loop
โŸณ

Condition-based

Do-While Loop
โ†ป

Execute then check

Loop Algorithm Visualization

1 Initialize counter: i = 0
2 Check condition: i < 5?
3 Execute loop body: console.log(i)
4 Increment: i++
5 Repeat from step 2

Try It Yourself - Loops

JavaScript

Arrays

Ordered collections of elements stored in a single variable

Array Visualization

Index 0
๐ŸŽ
"apple"
Index 1
๐ŸŒ
"banana"
Index 2
๐ŸŠ
"orange"
Arrays use zero-based indexing: first element is at index 0

Common Array Operations

Operation Method Description
Add to end push() Adds element to end of array
Remove from end pop() Removes and returns last element
Add to start unshift() Adds element to beginning
Remove from start shift() Removes and returns first element
Find length length Returns number of elements

Try It Yourself - Arrays

JavaScript

Strings

Sequences of characters used to represent text

String Operations

Enter text to analyze

Try It Yourself - Strings

JavaScript

Functions

Reusable blocks of code that perform specific tasks

Function Workflow

Function Execution Flow

1 Function Call: Invoke function with arguments
โ†“
2 Parameter Binding: Arguments mapped to parameters
โ†“
3 Execute Body: Run function code
โ†“
4 Return Value: Send result back to caller

Try It Yourself - Functions

JavaScript

Recursion

Functions that call themselves to solve problems

Recursion Algorithm

Factorial(5) Recursion

1 Call: factorial(5) โ†’ 5 * factorial(4)
โ†“
2 Call: factorial(4) โ†’ 4 * factorial(3)
โ†“
3 Call: factorial(3) โ†’ 3 * factorial(2)
โ†“
4 Base Case: factorial(1) โ†’ returns 1
โ†‘
5 Unwind: 3 * 2 * 1 = 6 โ†’ 4 * 6 = 24 โ†’ 5 * 24 = 120

Try It Yourself - Recursion

JavaScript

Scope

The accessibility and visibility of variables in different parts of code

Scope Levels

๐ŸŒ Global Scope

Accessible everywhere in the program

๐Ÿ  Function Scope

Accessible only within the function

๐Ÿ“ฆ Block Scope

Accessible only within the block { }

Try It Yourself - Scope

JavaScript

Type Casting

Converting values from one data type to another

Type Conversion Examples

String โ†’ Number
"42" โ†’ 42

Number("42")

Number โ†’ String
42 โ†’ "42"

String(42)

Boolean โ†’ Number
true โ†’ 1

Number(true)

Number โ†’ Boolean
0 โ†’ false

Boolean(0)

Try It Yourself - Type Casting

JavaScript

Bits and Bytes

The fundamental units of digital information

Understanding Bits and Bytes

1 Byte = 8 Bits

1
0
1
1
0
1
0
1

Each bit can be 0 or 1

Unit Size Example
Bit 1 bit 0 or 1
Nibble 4 bits 1011
Byte 8 bits 10110101
Kilobyte (KB) 1024 bytes Small text file
Megabyte (MB) 1024 KB High-res image
Gigabyte (GB) 1024 MB HD movie

Interactive Byte Builder

Click bits to toggle them on/off:

0
0
0
0
0
0
0
0
Binary: 00000000 | Decimal: 0

Number Systems Overview

Understanding different bases for representing numbers

What is a Number System?

A number system is a way of representing numbers using a specific set of symbols or digits. The base (or radix) determines how many unique digits are available.

Common Number Systems

2 Binary (Base-2): Uses only 0 and 1. Foundation of all digital computing.
8 Octal (Base-8): Uses 0-7. Commonly used in Unix file permissions.
10 Decimal (Base-10): Uses 0-9. The standard system humans use daily.
16 Hexadecimal (Base-16): Uses 0-9 and A-F. Compact representation of binary.

Number System Comparison

Decimal Binary (Base-2) Octal (Base-8) Hexadecimal (Base-16)
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010
20101002414
321000004020
64100000010040
100110010014464
25511111111377FF

Positional Notation Formula

Any number in any base can be calculated using positional notation:

Number = dn ร— basen + dn-1 ร— basen-1 + ... + d1 ร— base1 + d0 ร— base0
Example: 1011โ‚‚ = 1ร—2ยณ + 0ร—2ยฒ + 1ร—2ยน + 1ร—2โฐ = 8 + 0 + 2 + 1 = 11โ‚โ‚€
Example: 2Aโ‚โ‚† = 2ร—16ยน + 10ร—16โฐ = 32 + 10 = 42โ‚โ‚€

Real-World Applications

Binary
๐Ÿ’พ

Computer memory, logic gates, networking

Octal
๐Ÿ”

Unix permissions (chmod 755)

Decimal
๐Ÿงฎ

Everyday counting, finance, measurements

Hexadecimal
๐ŸŽจ

Colors (#FF5733), memory addresses

Binary Numbers (Base-2)

Base-2 number system using only 0s and 1s

Binary to Decimal Conversion

Binary: 1011 โ†’ Decimal: 11

Position 3 2 1 0
Power of 2 2ยณ = 8 2ยฒ = 4 2ยน = 2 2โฐ = 1
Binary digit 1 0 1 1
Calculation 1 ร— 8 = 8 0 ร— 4 = 0 1 ร— 2 = 2 1 ร— 1 = 1
Sum: 8 + 0 + 2 + 1 = 11

Binary Converter

Result will appear here

Try It Yourself - Binary

JavaScript

Octal Numbers (Base-8)

Number system using digits 0-7

Understanding Octal

Octal is a base-8 number system that uses digits 0 through 7. Each position represents a power of 8.

Octal: 157โ‚ˆ โ†’ Decimal: 111โ‚โ‚€

Position 2 1 0
Power of 8 8ยฒ = 64 8ยน = 8 8โฐ = 1
Octal digit 1 5 7
Calculation 1 ร— 64 = 64 5 ร— 8 = 40 7 ร— 1 = 7
Sum: 64 + 40 + 7 = 111โ‚โ‚€

Octal in Unix/Linux Permissions

Octal is commonly used for file permissions in Unix-based systems:

Octal Binary Permissions Description
0000---No permissions
1001--xExecute only
2010-w-Write only
3011-wxWrite + Execute
4100r--Read only
5101r-xRead + Execute
6110rw-Read + Write
7111rwxAll permissions
Example: chmod 755
7 (Owner: rwx) | 5 (Group: r-x) | 5 (Others: r-x)

Interactive Octal Converter

Result will appear here

Try It Yourself - Octal

JavaScript

Binary-Octal Relationship

Each octal digit represents exactly 3 binary digits (bits):

0
000
1
001
2
010
3
011
4
100
5
101
6
110
7
111
Example: Binary 101110โ‚‚ = Octal 56โ‚ˆ (group: 101 | 110 = 5 | 6)

Decimal Numbers (Base-10)

The standard number system used in everyday life

Understanding Decimal

Decimal is a base-10 number system that uses digits 0 through 9. It's the most familiar number system because it's what we use in daily life. The name "decimal" comes from the Latin word "decem," meaning ten.

Decimal Number: 3,456

Position Thousands Hundreds Tens Ones
Power of 10 10ยณ = 1000 10ยฒ = 100 10ยน = 10 10โฐ = 1
Digit 3 4 5 6
Value 3 ร— 1000 = 3000 4 ร— 100 = 400 5 ร— 10 = 50 6 ร— 1 = 6
Sum: 3000 + 400 + 50 + 6 = 3,456

Why Base-10?

Humans likely adopted base-10 because we have 10 fingers, making it natural for counting.

Historical
๐Ÿ‘‹

10 fingers = base-10

Universal
๐ŸŒ

Used worldwide

Intuitive
๐Ÿง 

Easy to learn

Decimal Arithmetic

Result will appear here

Decimal Representations

Type Example Description
Integer 42 Whole numbers
Decimal/Float 3.14159 Numbers with fractions
Scientific Notation 6.022e23 Very large/small numbers
Percentage 75% Parts per hundred
Negative -10 Below zero

Try It Yourself - Decimal Operations

JavaScript

Hexadecimal Numbers (Base-16)

Base-16 number system using 0-9 and A-F

Hexadecimal Chart

Decimal Binary Hexadecimal
000000
100011
101010A
111011B
121100C
131101D
141110E
151111F
161000010
25511111111FF

Color Hex Codes

Hexadecimal is commonly used in web colors:

Red
#FF0000
Green
#00FF00
Blue
#0000FF
Gold
#FFD700

Try It Yourself - Hexadecimal

JavaScript

Universal Base Converter

Convert numbers between any number systems (Base 2-36)

Multi-Base Converter

Enter a number to convert it to multiple bases

Custom Base Converter

Convert between any bases from 2 to 36

Understanding Different Bases

Base Name Digits Used Example
2Binary0, 11010โ‚‚ = 10โ‚โ‚€
3Ternary0, 1, 2102โ‚ƒ = 11โ‚โ‚€
4Quaternary0-322โ‚„ = 10โ‚โ‚€
5Quinary0-420โ‚… = 10โ‚โ‚€
6Senary0-514โ‚† = 10โ‚โ‚€
7Septenary0-613โ‚‡ = 10โ‚โ‚€
8Octal0-712โ‚ˆ = 10โ‚โ‚€
10Decimal0-910โ‚โ‚€ = 10โ‚โ‚€
12Duodecimal0-9, A-BAโ‚โ‚‚ = 10โ‚โ‚€
16Hexadecimal0-9, A-FAโ‚โ‚† = 10โ‚โ‚€
20Vigesimal0-9, A-JAโ‚‚โ‚€ = 10โ‚โ‚€
32Base32A-Z, 2-7 (standard)Used in encoding
36Base360-9, A-ZAโ‚ƒโ‚† = 10โ‚โ‚€
60SexagesimalComplex symbolsUsed in time (60 min)

Conversion Algorithm Visualization

Base Conversion Algorithm (Any Base โ†’ Decimal โ†’ Any Base)

1 Parse Input: Read number in source base (e.g., "1A" in base-16)
โ†“
2 Convert to Decimal: Use positional notation (1ร—16ยน + 10ร—16โฐ = 26)
โ†“
3 Convert to Target Base: Repeatedly divide by target base
โ†“
4 Read Remainders: Collect remainders in reverse order
โ†“
5 Format Output: Convert digits to appropriate symbols

Try It Yourself - Base Conversion

JavaScript

Real-World Applications of Different Bases

Base-2 (Binary)
๐Ÿ’ป

All digital computers

Base-8 (Octal)
๐Ÿ”ง

Unix permissions

Base-10 (Decimal)
๐Ÿ“Š

Human counting

Base-12 (Dozen)
๐Ÿฅš

Eggs, inches (12/foot)

Base-16 (Hex)
๐ŸŽจ

Colors, memory addresses

Base-60 (Sexagesimal)
โฐ

Time, angles (60 sec/min)

Boolean Algebra

Logic operations with true and false values

Boolean Operators

AND (&&) - Both must be true

ABA && B
falsefalsefalse
falsetruefalse
truefalsefalse
truetruetrue

OR (||) - At least one must be true

ABA || B
falsefalsefalse
falsetruetrue
truefalsetrue
truetruetrue

NOT (!) - Inverts the value

A!A
falsetrue
truefalse

Try It Yourself - Boolean Algebra

JavaScript

Input and Output

Getting data from users and displaying results

I/O Workflow

Input โ†’ Process โ†’ Output

1 Input: Receive data from user (keyboard, mouse, file, etc.)
โ†“
2 Validation: Check if input is valid and safe
โ†“
3 Processing: Perform operations on the data
โ†“
4 Output: Display results to user (console, screen, file, etc.)

Interactive I/O Demo

Enter your information to see the output

Common Output Methods

Method Description Example
console.log() Print to console console.log("Hello")
alert() Show popup dialog alert("Warning!")
document.write() Write to HTML page document.write("Text")
innerHTML Update HTML element elem.innerHTML = "New"