Skip to content

Commit

Permalink
Basics!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyiho committed Sep 29, 2023
1 parent 11fd511 commit 6f14402
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 4 deletions.
39 changes: 39 additions & 0 deletions _notebooks/2023-08-29-basics-of-js.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,45 @@
"}\n",
"</script>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Code ###\n",
"\n",
"<p><button onclick=\"CompareScores()\">Score Comparison</button></p>\n",
"<script>\n",
" function CompareScores(){\n",
" // Get input for player As score\n",
" var playerAScore = prompt(\"Enter Player A's score:\");\n",
" playerAScore = parseInt(playerAScore);\n",
"\n",
" // Check if the input for player A is valid\n",
" if (isNaN(playerAScore)) {\n",
" console.log(\"Please enter a valid number for Player A's score.\");\n",
" } else {\n",
" // Get input for player Bs score\n",
" var playerBScore = prompt(\"Enter Player B's score:\");\n",
" playerBScore = parseInt(playerBScore);\n",
"\n",
" // Check if the input for player B is valid\n",
" if (isNaN(playerBScore)) {\n",
" console.log(\"Please enter a valid number for Player B's score.\");\n",
" } else {\n",
" // Compare the scores and log the result\n",
" if (playerAScore > playerBScore) {\n",
" console.log(\"Player A is winning!\");\n",
" } else if (playerBScore > playerAScore) {\n",
" console.log(\"Player B is winning!\");\n",
" } else {\n",
" console.log(\"It's a tie! Both players have the same score.\");\n",
" }\n",
" }\n",
" }\n",
" }\n",
"</script>"
]
}
],
"metadata": {
Expand Down
110 changes: 106 additions & 4 deletions _notebooks/2023-08-30-basics-js-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,112 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"execution_count": 1,
"metadata": {
"vscode": {
"languageId": "html"
}
},
"outputs": [
{
"data": {
"text/html": [
"<script>\n",
"// Create an object representing Zafeer Ahmed\n",
"var person = {\n",
" name: \"Trystan Schmits\",\n",
" age: 16,\n",
" currentClasses: [\"AP Calc\", \"Us History\", \"American Lit\", \"CSSE\", \"Physics\"],\n",
" interests: [\"Soccer\", \"Coding\", \"games\"],\n",
" favoriteBooks: [\"Harry Potter\", \"The Lion, the Witch, and The Wardrobe\"],\n",
"};\n",
" \n",
"// Print the entire object\n",
"console.log(\"Original Object:\");\n",
"console.log(person);\n",
"\n",
"// Manipulate the arrays within the object\n",
"person.currentClasses.push(\"Spanish 7\");\n",
"person.interests.splice(2, 1,\"History 3\");\n",
"\n",
"// Print the entire object after manipulation\n",
"console.log(\"\\nObject after Manipulation:\");\n",
"console.log(person);\n",
"\n",
"// Perform mathematical operations on fields in the object\n",
"var ageInFiveYears = person.age + 5;\n",
"var numberOfClasses = person.currentClasses.length;\n",
"\n",
"// Print the results with context\n",
"console.log(\"\\nMathematical Operations:\");\n",
"console.log(\"Age in five years:\", ageInFiveYears);\n",
"console.log(\"Number of current classes:\", numberOfClasses);\n",
"\n",
"// Use typeof to determine the types of fields\n",
"var typeOfName = typeof perso.name;\n",
"var typeOfInterests = typeof person.interests;\n",
"var typeOfAge = typeof person.age;\n",
"\n",
"// Print the types of fields\n",
"console.log(\"\\nTypes of Fields:\");\n",
"console.log(\"Type of 'name':\", typeOfName);\n",
"console.log(\"Type of 'interests':\", typeOfInterests);\n",
"console.log(\"Type of 'age':\", typeOfAge);\n",
"</script>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"<script>\n",
"// Create an object representing Zafeer Ahmed\n",
"var person = {\n",
" name: \"Trystan Schmits\",\n",
" age: 16,\n",
" currentClasses: [\"AP Calc\", \"Us History\", \"American Lit\", \"CSSE\", \"Physics\"],\n",
" interests: [\"Soccer\", \"Coding\", \"games\"],\n",
" favoriteBooks: [\"Harry Potter\", \"The Lion, the Witch, and The Wardrobe\"],\n",
"};\n",
" \n",
"// Print the entire object\n",
"console.log(\"Original Object:\");\n",
"console.log(person);\n",
"\n",
"// Manipulate the arrays within the object\n",
"person.currentClasses.push(\"Spanish 7\");\n",
"person.interests.splice(2, 1,\"History 3\");\n",
"\n",
"// Print the entire object after manipulation\n",
"console.log(\"\\nObject after Manipulation:\");\n",
"console.log(person);\n",
"\n",
"// Perform mathematical operations on fields in the object\n",
"var ageInFiveYears = person.age + 5;\n",
"var numberOfClasses = person.currentClasses.length;\n",
"\n",
"// Print the results with context\n",
"console.log(\"\\nMathematical Operations:\");\n",
"console.log(\"Age in five years:\", ageInFiveYears);\n",
"console.log(\"Number of current classes:\", numberOfClasses);\n",
"\n",
"// Use typeof to determine the types of fields\n",
"var typeOfName = typeof person.name;\n",
"var typeOfInterests = typeof person.interests;\n",
"var typeOfAge = typeof person.age;\n",
"\n",
"// Print the types of fields\n",
"console.log(\"\\nTypes of Fields:\");\n",
"console.log(\"Type of 'name':\", typeOfName);\n",
"console.log(\"Type of 'interests':\", typeOfInterests);\n",
"console.log(\"Type of 'age':\", typeOfAge);\n",
"</script>"
]
}
],
"metadata": {
Expand Down

0 comments on commit 6f14402

Please sign in to comment.