CS111 requirements blog
My blog on the requirements of CS111.
| Topic | Description | Code Review Focus | Met | Unmet |
|---|---|---|---|---|
| Control Structures | ||||
| Iteration | Use loops for game object arrays, animation frames | for, forEach, while loops |
✅ | ☐ |
| Conditionals | Implement collision detection, state transitions | if/else, nested conditions |
✅ | ☐ |
| Nested Conditions | Complex game logic (e.g., power-up + collision + direction) | Multi-level conditionals | ☐ | ✅ |
| Data Types | ||||
| Numbers | Position, velocity, score tracking | Numeric properties | ☐ | ✅ |
| Strings | Character names, sprite paths, game states | String manipulation | ✅ | ☐ |
| Booleans | Flags (isJumping, isPaused, isVulnerable) | Boolean logic | ✅ | ☐ |
| Arrays | Game object collections, level data | Array operations | ✅ | ☐ |
| Objects (JSON) | Configuration objects, sprite data | Object literals | ✅ | ☐ |
| Operators | ||||
| Mathematical | Physics calculations (gravity, velocity, collision) | +, -, *, / in physics |
✅ | ☐ |
| String Operations | Path concatenation, text display | Template literals, concatenation | ✅ | ☐ |
| Boolean Expressions | Compound conditions in game logic | &&, \|\|, ! |
✅ | ☐ |
Here are some code runners for each lesson:
Code Runner Challenge
Classes and methods
View IPYNB Source
%%js
// CODE_RUNNER: Classes and methods
class Cat {
constructor(name) {
this.name = name;
this.hunger = 100; // 100 = full, 0 = starving
}
eat() {
this.hunger = Math.min(100, this.hunger + 30);
console.log(this.name + " eats some food. Hunger: " + this.hunger);
}
meow() {
if (this.hunger < 40) {
console.log(this.name + " meows loudly... they're hungry!");
} else {
console.log(this.name + " meows contentedly.");
}
}
}
let myCat = new Cat("Whiskers");
myCat.meow(); // contentedly
myCat.hunger = 20;
myCat.meow(); // loudly/hungry
myCat.eat(); // hunger restored
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Strings
View IPYNB Source
%%js
// CODE_RUNNER: Strings
// Create three strings of varying lengths
let string1 = "Hello";
let string2 = "JavaScript";
let string3 = "Programming";
// Find and print the length of each string
console.log("Lengths:");
console.log(`"${string1}" has length: ${string1.length}`);
console.log(`"${string2}" has length: ${string2.length}`);
console.log(`"${string3}" has length: ${string3.length}`);
// Find and print first and last character of each string
console.log("\nFirst and Last Characters:");
console.log(`"${string1}": first='${string1[0]}', last='${string1[string1.length-1]}'`);
console.log(`"${string2}": first='${string2[0]}', last='${string2[string2.length-1]}'`);
console.log(`"${string3}": first='${string3[0]}', last='${string3[string3.length-1]}'`);
// Concatenate all three strings into a sentence
let sentence = string1 + " " + string2 + " " + string3;
console.log("\nConcatenated sentence:");
console.log(sentence);
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Math operations
View IPYNB Source
%%js
// CODE_RUNNER: Math operations
const y = [15]
for(let num in y){if (y % 5 === 0) {console.log(y + " is divisible by 5 and odd")} else (console.log(y + " is not divisible by 5"))}
const a = 4 * 3;
const b = 11 * 2;
const sum = 8 * 4;
console.log(a + b + sum)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
JSON Data structures
View IPYNB Source
%%js
// CODE_RUNNER: JSON Data structures
// 1. Create a JavaScript object named `resume` with the following properties:
const resume = {
fullName: "Rohan Sharma", // Add your full name
email: "rohansharma15017@gmail.com", // Add your email
education: "Grade 9", // Add your grade
address: { // Nested object
city: "San Diego",
state: "California",
country: "United States of America"
},
skills: ["Managing JSON objects", "Coding in Javascript", "Playing Lacrosse"] // Array of strings
};
// 2. Access and display properties for full name, email, and city using dot notation. Look at section 1.
console.log(resume.fullName);
console.log(resume.address.city);
// 3. Convert the `resume` JavaScript object into a JSON string and store it in a variable named `jsonString`, then log the JSON string to the console. Look at Section 3.
const jsonString = JSON.stringify(resume);
console.log(jsonString);
// 4. Parse the JSON string back into a JavaScript object and store it in a variable named `parsedResume`, then log the object to the console. Look at Section 3.
const parsedResume = JSON.parse(jsonString);
console.log(parsedResume);
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Data abstraction
View IPYNB Source
%%js
// CODE_RUNNER: Data abstraction
function calculator(num1, num2, operator) {
let result;
if (operator === "+") {
result = num1 + num2;
} else if (operator === "-") {
result = num1 - num2;
} else if (operator === "*") {
result = num1 * num2;
} else if (operator === "/") {
result = num1 / num2;
} else {
result = "Invalid operator";
}
const nothing = 0
for (let i = 0; i < 3; i++) {
nothing += 0;
}
return result;
}
console.log(calculator(10, 5, "+"));
console.log(calculator(10, 5, "-"));
console.log(calculator(10, 5, "*"));
console.log(calculator(10, 5, "/"));
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Iterations
View IPYNB Source
%%js
// CODE_RUNNER: Iterations
let fruits = ["Heart Shaped Herb", "Yami Yami no Mi", "Gomu Gomu no Mi", "Monkey D. Luffy"];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}
for (let i = 0; i < fruits.length; i++) {
if (i % 2 === 0) {console.log (fruits[i] + " is technically an odd fruit in the iteration");
}
}
for (let i = 0; i < fruits.length; i++) {
if (i === 3) {console.log (fruits[i] + " is not a fruit," + fruits[i] + " is a character!")}
else {console.log (fruits[i] + " is just a fruit :(")}
}
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Code Runner Challenge
Arrays
View IPYNB Source
%%js
// CODE_RUNNER: Arrays
// TODO: Write your code here for Exercise 3
// Create the numbers array
// Loop through and print each number
// Print each number multiplied by 2
// Calculate and print the sum
console.log ("Normal numbers")
console.log()
const NUMBER = [10, 25, 30, 15, 20]
for(let num of NUMBER) {console.log (num)}
console.log()
console.log("Doubled numbers")
console.log()
for(let num of NUMBER) {console.log (num * 2)}
console.log()
console.log("sum")
console.log()
let sum = 0;
for (let num of NUMBER) {
sum += num;
}
console.log(sum)
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...