generated from nighthawkcoders/student_2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
746 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "yaml" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"---\n", | ||
"comments: True\n", | ||
"layout: post\n", | ||
"title: Iteration Homework\n", | ||
"description: An intro to data abstraction\n", | ||
"permalink: /csse/javascript/fundamentals/iteration/hw\n", | ||
"categories: [CSSE JavaScript Fundamentals]\n", | ||
"author: Kian Zhu, Michael Xu and Srinaga Pillutla\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Homework Assignment: for Loop Challenge\n", | ||
"Task: Create a program that does the following:\n", | ||
"\n", | ||
"Initialize an array with the names of five of your favorite movies.\n", | ||
"Use a for loop to iterate through the array and print each movie name to the console.\n", | ||
"After printing all movie names, print a message indicating how many movies you listed." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# **Homework**\n", | ||
"\n", | ||
"Create a **3 by 3, 2D list** that represents a **tictactoe board**.\n", | ||
"Use **\"X\"** for X, **\"O\"** for O, and **None** for empty tiles.\n", | ||
"\n", | ||
"Ex. board = [[\"X\",\"None\",\"O\"], \n", | ||
"       [\"X\",\"O\",\"None\"], \n", | ||
"       [\"O\",\"None\",\"X\"]]\n", | ||
"\n", | ||
"Iterate over the board and **identify whether it is player X's or player O's turn.**\n", | ||
"\n", | ||
"**Hint**: count the number of moves(non-None). (X goes first)\n", | ||
"\n", | ||
"**Optional**: use console.error() to report an error if the board is illegal (ex. 7 \"X\"s and 2 \"O\"s)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## H.W application of While Loops. \n", | ||
"\n", | ||
"Create the Outer Loop:\n", | ||
"\n", | ||
"Use a while loop that runs while outerFactor is less than or equal to 10.\n", | ||
"Initialize the Inner Loop Variable:\n", | ||
"\n", | ||
"Inside the outer loop, create another variable called innerFactor and set it to 1.\n", | ||
"Create the Inner Loop:\n", | ||
"\n", | ||
"Inside the outer loop, use another while loop that runs while innerFactor is less than or equal to 10.\n", | ||
"Calculate the Product:\n", | ||
"\n", | ||
"Inside the inner loop, calculate the product of outerFactor and innerFactor.\n", | ||
"Print the Product:\n", | ||
"\n", | ||
"Print the product using console.log(), formatting the output neatly.\n", | ||
"Increment the Inner Loop Variable:\n", | ||
"\n", | ||
"After printing the product, increment innerFactor by 1.\n", | ||
"Move to the Next Line:\n", | ||
"\n", | ||
"After the inner loop finishes, print a new line to separate rows.\n", | ||
"Increment the Outer Loop Variable:\n", | ||
"\n", | ||
"Increment outerFactor by 1 to move to the next row in the table." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"---\n", | ||
"comments: True\n", | ||
"layout: post\n", | ||
"title: Iteration For Loops\n", | ||
"description: An intro to data abstraction\n", | ||
"permalink: /csse/javascript/fundamentals/iteration/p1\n", | ||
"categories: [CSSE JavaScript Fundamentals]\n", | ||
"author: Kian Zhu\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# What is for loops" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"A for loop is a control flow statement that allows you to execute a block of code a certain number of times. It's particularly useful when you know in advance how many times you want to iterate through a block of code." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Syntax of a for Loop\n", | ||
"The syntax of a for loop consists of three main parts:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%js \n", | ||
"for (initialization; condition; increment) {\n", | ||
" // Code to be executed on each iteration\n", | ||
"}\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Initialization: This sets up a counter variable and runs once at the beginning of the loop.\n", | ||
"\n", | ||
"Condition: Before each iteration, the loop checks this condition. If it's true, the loop continues; if false, the loop ends.\n", | ||
"\n", | ||
"Increment: This updates the counter variable after each iteration." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Example of a for Loop" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%js \n", | ||
"for (let i = 1; i <= 5; i++) {\n", | ||
" console.log(i);\n", | ||
"}\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Explanation:\n", | ||
"\n", | ||
"Initialization: let i = 1 sets the counter variable i to 1.\n", | ||
"\n", | ||
"Condition: i <= 5 checks if i is less than or equal to 5.\n", | ||
"\n", | ||
"Increment: i++ increases i by 1 after each iteration." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Output\n", | ||
"1\n", | ||
"\n", | ||
"2\n", | ||
"\n", | ||
"3\n", | ||
"\n", | ||
"4\n", | ||
"\n", | ||
"5\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Advanced Usage: Looping Through Arrays\n", | ||
"You can use a for loop to iterate over elements in an array. Here’s an example:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "javascript" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%js \n", | ||
"let fruits = [\"apple\", \"banana\", \"cherry\"];\n", | ||
"\n", | ||
"for (let i = 0; i < fruits.length; i++) {\n", | ||
" console.log(fruits[i]);\n", | ||
"}\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### output\n", | ||
"apple\n", | ||
"\n", | ||
"banana\n", | ||
"\n", | ||
"cherry\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## popcorn 1\n", | ||
"Calculate the Sum\n", | ||
" Write a for loop that calculates the sum of all even numbers from 1 to 20. Output the result to the console.\n", | ||
"\n", | ||
"**Hint**: Any number divided by two results in a remainder of 1 for odd numbers and 0 for even numbers. The modulo operator (`%`) helps you determine this condition. The statement `if (n % 2 == 0)` would be true when `n` is even." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.