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
Key Programming Paradigms
Step-by-step instructions
Objects & classes
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
let name; - Reserve memory
name = "Ashok"; - Assign initial value
console.log(name); - Read value
name = "Ashok"; - Change value
Interactive Variable Demo
Try It Yourself - Variables
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
Data Types
Different kinds of data that can be stored and manipulated
Primitive Data Types
Integers & decimals
Text data
True or false
No value assigned
Intentionally empty
Try It Yourself - Data Types
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
Try It Yourself - Operators
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
If Statements
Making decisions in code based on conditions
Conditional Logic Workflow
If-Else Decision Flow
Interactive Decision Demo
Try It Yourself - If Statements
Loops
Repeating code execution multiple times
Loop Types
Fixed iterations
Condition-based
Execute then check
Loop Algorithm Visualization
Try It Yourself - Loops
Arrays
Ordered collections of elements stored in a single variable
Array Visualization
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
Strings
Sequences of characters used to represent text
String Operations
Try It Yourself - Strings
Functions
Reusable blocks of code that perform specific tasks
Function Workflow
Function Execution Flow
Try It Yourself - Functions
Recursion
Functions that call themselves to solve problems
Recursion Algorithm
Factorial(5) Recursion
Try It Yourself - Recursion
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
Type Casting
Converting values from one data type to another
Type Conversion Examples
Number("42")
String(42)
Number(true)
Boolean(0)
Try It Yourself - Type Casting
Bits and Bytes
The fundamental units of digital information
Understanding Bits and Bytes
1 Byte = 8 Bits
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:
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
Number System Comparison
| Decimal | Binary (Base-2) | Octal (Base-8) | Hexadecimal (Base-16) |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 20 | 10100 | 24 | 14 |
| 32 | 100000 | 40 | 20 |
| 64 | 1000000 | 100 | 40 |
| 100 | 1100100 | 144 | 64 |
| 255 | 11111111 | 377 | FF |
Positional Notation Formula
Any number in any base can be calculated using positional notation:
Real-World Applications
Computer memory, logic gates, networking
Unix permissions (chmod 755)
Everyday counting, finance, measurements
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 |
Binary Converter
Try It Yourself - Binary
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 |
Octal in Unix/Linux Permissions
Octal is commonly used for file permissions in Unix-based systems:
| Octal | Binary | Permissions | Description |
|---|---|---|---|
| 0 | 000 | --- | No permissions |
| 1 | 001 | --x | Execute only |
| 2 | 010 | -w- | Write only |
| 3 | 011 | -wx | Write + Execute |
| 4 | 100 | r-- | Read only |
| 5 | 101 | r-x | Read + Execute |
| 6 | 110 | rw- | Read + Write |
| 7 | 111 | rwx | All permissions |
7 (Owner: rwx) | 5 (Group: r-x) | 5 (Others: r-x)
Interactive Octal Converter
Try It Yourself - Octal
Binary-Octal Relationship
Each octal digit represents exactly 3 binary digits (bits):
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 |
Why Base-10?
Humans likely adopted base-10 because we have 10 fingers, making it natural for counting.
10 fingers = base-10
Used worldwide
Easy to learn
Decimal Arithmetic
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
Hexadecimal Numbers (Base-16)
Base-16 number system using 0-9 and A-F
Hexadecimal Chart
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
| 16 | 10000 | 10 |
| 255 | 11111111 | FF |
Color Hex Codes
Hexadecimal is commonly used in web colors:
Try It Yourself - Hexadecimal
Universal Base Converter
Convert numbers between any number systems (Base 2-36)
Multi-Base Converter
Custom Base Converter
Understanding Different Bases
| Base | Name | Digits Used | Example |
|---|---|---|---|
| 2 | Binary | 0, 1 | 1010โ = 10โโ |
| 3 | Ternary | 0, 1, 2 | 102โ = 11โโ |
| 4 | Quaternary | 0-3 | 22โ = 10โโ |
| 5 | Quinary | 0-4 | 20โ = 10โโ |
| 6 | Senary | 0-5 | 14โ = 10โโ |
| 7 | Septenary | 0-6 | 13โ = 10โโ |
| 8 | Octal | 0-7 | 12โ = 10โโ |
| 10 | Decimal | 0-9 | 10โโ = 10โโ |
| 12 | Duodecimal | 0-9, A-B | Aโโ = 10โโ |
| 16 | Hexadecimal | 0-9, A-F | Aโโ = 10โโ |
| 20 | Vigesimal | 0-9, A-J | Aโโ = 10โโ |
| 32 | Base32 | A-Z, 2-7 (standard) | Used in encoding |
| 36 | Base36 | 0-9, A-Z | Aโโ = 10โโ |
| 60 | Sexagesimal | Complex symbols | Used in time (60 min) |
Conversion Algorithm Visualization
Base Conversion Algorithm (Any Base โ Decimal โ Any Base)
Try It Yourself - Base Conversion
Real-World Applications of Different Bases
All digital computers
Unix permissions
Human counting
Eggs, inches (12/foot)
Colors, memory addresses
Time, angles (60 sec/min)
Boolean Algebra
Logic operations with true and false values
Boolean Operators
AND (&&) - Both must be true
| A | B | A && B |
|---|---|---|
| false | false | false |
| false | true | false |
| true | false | false |
| true | true | true |
OR (||) - At least one must be true
| A | B | A || B |
|---|---|---|
| false | false | false |
| false | true | true |
| true | false | true |
| true | true | true |
NOT (!) - Inverts the value
| A | !A |
|---|---|
| false | true |
| true | false |
Try It Yourself - Boolean Algebra
Input and Output
Getting data from users and displaying results
I/O Workflow
Input โ Process โ Output
Interactive I/O Demo
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" |