CS111 Evidence: Data Types
Data Types Evidence
🔹 Data Types: Numbers
- 📌 Requirement: Utilize numeric properties to track positions, velocities, and scores, while performing complex arithmetic operations and functional math tracking.
- 📝 Assessment Method: Code review of numeric properties, type conversion functions, and mathematical expressions.
- What it is: The Number data type handles quantitative values including integers and floating-point decimals. In JavaScript, numeric operations use mathematical symbols like `+`, `-`, `*`, `/`, and exponentiation (`**`) to transform data.
- How it works: String inputs from interface text fields are explicitly transformed into real numerical data using the global `Number()` method. Once converted, values can be mathematically scaled, squared, or evaluated through specialized calculation functions.
- Why it helps: It prevents errors caused by implicit type coercion (like unintentionally combining text strings instead of adding numbers). This guarantees that calculation steps, physics vectors, and operational frameworks produce precise mathematical values.
// EVIDENCE: DATA TYPES - NUMBERS
// Source: Variables Homework & Math Expressions Homework
// Part 1: Type Conversion and Basic Arithmetic
function calculateMagic() {
let input = document.getElementById("magicInput"); // Retrieves input element
// Explicit Type Conversion: Transforming a string input value into a Number data type
let magicNumber = Number(input.value);
// Using Arithmetic Operators (* for multiplication, ** for exponentiation, / for division)
let doubled = magicNumber * 2;
let squared = magicNumber ** 2; // Exponentiation operator
let half = magicNumber / 2; // Division operator
return { doubled, squared, half };
}
// Part 2: Isolated Math Expression Operations
function MathOperationsReview() {
let num1 = 6; // Numeric property assignment (Integer)
let num2 = 3; // Numeric property assignment (Integer)
// Complex operator precedence evaluation
let part1_result = (num1 * num2) + (num1 / 2); // Evaluates to 21
// Storing calculated equation values back into a numeric variable
let total = (num1 / num2) + 2 ** 3; // Evaluates to 10
return { part1_result, total };
}
🔹 Data Types: Strings
- 📌 Requirement: Implement text strings to store character names, configure sprite path directions, and handle text manipulations.
- 📝 Assessment Method: Code review of string assignments, literal formatting, and text combination operations.
- What it is: A String is a collection of characters used to store and manipulate text data. Strings are wrapped inside single quotes, double quotes, or backticks.
- How it works: Text blocks are joined together through string concatenation using the `+` operator. Alternatively, template literals wrapped in backticks (`` ` ``) allow variables to be evaluated directly inside a string template using `${}` formatting.
- Why it helps: It enables fluid text communication and dynamic asset loading. String combinations make it easy to merge baseline text descriptions with changing variables like names, paths, or scores before rendering them to the screen.
// EVIDENCE: DATA TYPES - STRINGS
// Source: Variables Homework
function StringManipulationReview() {
// String Literals: Initializing string sequences using double quotes
let firstName = "Anika";
let lastName = "Seksaria";
let favoriteFood = "pizza";
// String Concatenation: Joining string variables and text literals using the + operator
let fullName = firstName + " " + lastName;
let baselineSentence = "My favorite food is " + favoriteFood + ".";
// Template Literals: Using backticks to embed dynamic variables inside a string template
let userName = "Anika";
let userAge = "14";
let templateOutput = `Hello ${userName}, you are ${userAge} years old.`;
return { fullName, baselineSentence, templateOutput };
}
🔹 Data Types: Booleans
- 📌 Requirement: Implement boolean logic and flags to track conditions such as state tracking, pass/fail thresholds, and true/false identity status.
- 📝 Assessment Method: Code review of boolean assignments, comparison operators, and conditional flags.
- What it is: A Boolean is a logical data type that can only hold one of two possible values:
trueorfalse. - How it works: Booleans can be explicitly assigned as raw states, or they can be dynamically generated by evaluating comparison rules (like using
>=to verify a score limit). - Why it helps: It serves as the foundation for digital decision loops. Boolean variables act as binary binary toggles that dictate whether a script should allow conditional operations to execute or bypass them entirely.
// EVIDENCE: DATA TYPES - BOOLEANS
// Source: GameLevelRedRidingHood1.js
class GameLevelRedRidingHood1 {
constructor(gameEnv, game) {
this.gameEnv = gameEnv;
this.gameControl = game;
// Boolean Flags: Toggles used to manage state changes during execution
this.continue = true; // Controls whether the stage loop keeps processing
this.scoreSubmitted = false; // Prevents multiple server requests for the same score
this.saveAttempted = false; // Monitors submission state for the leaderboard score
this.isGrounded = false; // Physics toggle tracking if player is on the floor
}
update() {
const player = this.gameEnv.gameObjects.find(obj => obj.id === 'player');
if (player) {
// Utilizing Boolean state logic for jumping conditions
if (player.pressedKeys?.[87] && this.isGrounded) {
this.vy = -10;
this.isGrounded = false; // Directly updates boolean state to clear ground lock
}
}
const currentScore = this.gameEnv.stats?.coinsCollected || 0;
// Evaluation: Generates a boolean value dynamically to route score triggers
if (currentScore >= 5 && !this.scoreSubmitted) {
this.scoreSubmitted = true; // Sets flag to true so this branch fires only once
// Formats submission window...
}
}
}
🔹 Data Types: Arrays
- 📌 Requirement: Implement sequential collections to track active entities, render layered groups, and manage item inventories.
- 📝 Assessment Method: Code review of array declarations, element additions, and iteration methods.
- What it is: An Array is an ordered list container capable of holding multiple items, references, or objects under a single structural variable name.
- How it works: Arrays group active runtime elements inside brackets `[]`. Standard operations utilize methods like `.push()` to append newly generated components to the end of the list or `.filter()` to drop destroyed items instantly.
- Why it helps: It prevents variable bloat. Instead of initializing independent tracking references for every projectile or background barrier individually, a single array framework holds them collectively to cycle through batch transformations safely.
// EVIDENCE: DATA TYPES - ARRAYS
// Source: GameLevelRedRidingHood1.js
class GameLevelRedRidingHood1 {
constructor(gameEnv, game) {
this.gameEnv = gameEnv;
this.gameControl = game;
// Array Declaration: Establishing an ordered collection to track game assets
this.cookies = [];
// Array Layout Configuration: Mapping coordinate pairs sequentially
const cookiePositions = [
{ x: 0.1, y: 0.8 },
{ x: 0.3, y: 0.75 },
{ x: 0.5, y: 0.8 },
{ x: 0.7, y: 0.75 },
{ x: 0.9, y: 0.8 }
];
// Array Processing Operation: Using .forEach() to step through positions
// and push newly instantiated elements into the arrays
cookiePositions.forEach((pos, index) => {
const cookie = new Coin({ id: `cookie-${index}`, INIT_POSITION: pos, SCALE_FACTOR: 12, value: 1, zIndex: 10 }, this.gameEnv);
this.cookies.push(cookie); // Appends element into local tracking array
this.gameEnv.gameObjects.push(cookie); // Appends element globally into environment engine array
});
}
}
🔹 Data Types: JSON Objects
- 📌 Requirement: Use JSON structures to organize and store game asset settings.
- 📝 Examples: Creating structured data blocks for things like
image_data_forestor player stats.
- What it is: A JSON object is a way to group data together using key-value pairs inside curly braces `{}`. It connects labels to information like numbers, text, or arrays.
- How it works: Configuration settings hold all the details for an item in one clean block. The game reads values directly out of this block using dot notation (like
pixels.width). - Why it helps: It centralizes your settings. Instead of creating random individual variables all over the place, you can keep all asset sizes, file paths, and rules stored safely in one structured block.
// EVIDENCE: DATA TYPES - OBJECTS (JSON STRUCTURES)
// Source: GameLevelRedRidingHood1.js
class GameLevelRedRidingHood1 {
constructor(gameEnv, game) {
this.gameEnv = gameEnv;
// Object Literal / Configuration Block: Storing structured, keyed data profiles
const sprite_data_red = {
id: 'player',
src: gameEnv.path + "/images/projects/red-riding/red.png",
SCALE_FACTOR: 5,
STEP_FACTOR: 1000,
ANIMATION_RATE: 50,
INIT_POSITION: { x: 0, y: gameEnv.innerHeight - (gameEnv.innerHeight / 5) },
pixels: { height: 192, width: 144 },
orientation: { rows: 4, columns: 3 },
down: { row: 0, start: 0, columns: 3 },
left: { row: 1, start: 0, columns: 3 },
right: { row: 2, start: 0, columns: 3 },
up: { row: 3, start: 0, columns: 3 },
keypress: { up: 87, left: 65, down: 83, right: 68 }
};
// Setting up the engine configuration array using the structured data profile
this.classes = [
{ class: Player, data: sprite_data_red }
];
}
}