BootCamp by Dr.Angela
1. Random Number Generation
- Generate random numbers
var n = Math.random();
- Returns a number between 0 (inclusive) and 1 (exclusive)
- Change range
Math.floor(n * x) + 1;- Generates a number between 1 and x
2. Control Statements – If / Else
- If / Else condition
if (track === "clear") { goStraight(); } else { turnRight(); }
- Tip : Use a flowchart to visualize logic
3. Comparators and Equality
- ===(is equal to), !==(is not equal to), >(greater than), <(less than), >=(greater than or equal to), <=(less than or equal to)
4. Combining Conditions
- &&(AND), ||(OR), !(NOT)
5. Arrays (Collections)
- ex)
var list = ["A", "B", "C"]; - Length :
list.length; - Access element :
list[x];// index starts from 0 - Check if value exists :
list.includes("A");// returns true or false
6. Adding Elements to Arrays
- Add to the end :
list.push("D");
7. While Loop
while (condition) { // do something }- Runs while the condition is true
- Used for state-based repetition
8. For Loop
for (let i = 0; i < 2; i++) { // do something }- Structure : (start; condition; change)
- Used to iterate a specific number of times
Top comments (0)