Programming With JS
Programming With JS
Course Outline
1. What is programming?
Course Outline
3.4. Functions
3.5. Conditionals
3.6. Loops
CodeLab Academy
Where your innovation journey begins!
1. What is Programming?
- The set of instructions you write for the computer is called Code
… Cont’d
- Explanation
- “console.log” is the instruction that tells the computer to display the text
- The computer follows this simple instruction and shows Hello, World! on the screen.
CodeLab Academy
Where your innovation journey begins!
- Link: https://scratch.mit.edu/
- Interactivity is you can do things on the page, and the page responds to your actions
- For example:
- Click a Button: When you click a button, something happens (e.g., a confirmation message pops up or
the button changes color).
CodeLab Academy
Where your innovation journey begins!
… Cont’d
<script>
function sayHello() {
alert("Hello, World!");
</script>
CodeLab Academy
Where your innovation journey begins!
… Cont’d
- Data types are the basic building blocks of data, representing a single kind of information
… Cont’d
- Variable is like a labeled box that holds information you want to use in a program
- It allows you to store a value (like a number, word, or answer) and refer to it by name later.
let score = 0;
// Updates score to 10
score = score + 10;
// Outputs: Score: 10
console.log("Score:", score);
CodeLab Academy
Where your innovation journey begins!
… Cont’d
2. const: used when the value will never change.
… Cont’d
… Cont’d
0 1 2 3 4 Index
Items
Negasi Kirubel Henok Mubarek Fermina
CodeLab Academy
Where your innovation journey begins!
… Cont’d
name: "John",
age: 25,
city: "New York"
};
… Cont’d
3.4. Functions
- Think of them like recipes: you write the steps once and reuse them whenever needed.
- Instead of repeating the same steps over and over, you simply "call" the function.
- By bundling tasks into functions, you simplify your code and make it more efficient and organized.
CodeLab Academy
Where your innovation journey begins!
… Cont’d
Example: Functions
function greet() {
console.log("Hello!");
… Cont’d
3.5. Conditional
- Conditionals allow your program to make decisions based on specific conditions (true or false).
- Use `if` to check a condition, and if it's true, the code inside will run.
- Add `else if` to check another condition if the first one isn't met.
- Use `else` to handle all other cases when no previous conditions are true.
CodeLab Academy
Where your innovation journey begins!
… Cont’d
Example: Conditionals
CodeLab Academy
Where your innovation journey begins!
… Cont’d
3.6. Loops
- Loops help you avoid repeating code manually, making tasks like counting or going through lists easier.
CodeLab Academy
Where your innovation journey begins!
… Cont’d
Example: Loops
CodeLab Academy
Where your innovation journey begins!
Assignment
Thank You
CodeLab Academy
Where your innovation journey begins!