Skip to content

Commit

Permalink
Merge pull request #558 from anikaagit/main
Browse files Browse the repository at this point in the history
Refined instructions based on team feedback. Updated popcorn hack 2 in the file 2024-10-26-nested_conditionals.ipynb
  • Loading branch information
jm1021 authored Nov 4, 2024
2 parents d55bd04 + 2bc4220 commit 5f052c6
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,35 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2><span style=\"font-family: Ariel; color:#94c4ff\">Example 2 - Booleans</span></h2>\n",
"<h2><span style=\"font-family: Ariel; color:#94c4ff\">Booleans with Nested Conditionals</span></h2>\n",
"\n",
"1. Write a code that checks if you can cook a meal at home. \n",
"2. Use the presence of hunger, and ingredients, to determine if cooking a meal is possible at home.\n",
"3. Use booleans in the code"
"\n",
"<p><span style=\"font-family: Arial\">A <b>boolean</b> is a data type that represents one of two possible values: <code>true</code> or <code>false</code>. Booleans are useful for decision-making in code, as they let us determine if specific conditions are met. For example, if we want to check if someone meets the age requirement for a concert or has a ticket, we might represent these conditions as booleans.</span></p>\n",
"\n",
"<p><span style=\"font-family: Arial\">A <b>nested boolean</b> is simply a boolean condition used inside another condition. When using <b>nested conditionals</b> (conditions inside other conditions), we can build complex decision-making logic. For example, we might check first if the person is old enough, and if they are, then check if they have a ticket. This kind of logic allows us to handle multiple conditions in a structured way.</span></p>\n",
"\n",
"<p><span style=\"font-family: Arial\">Here’s an example:</span></p>\n",
"\n",
"```javascript\n",
"let isOldEnough = true; // Boolean indicating if the person meets the age requirement\n",
"let hasTicket = false; // Boolean indicating if the person has a ticket\n",
"\n",
"if (isOldEnough) { // Check if the person meets the age requirement\n",
" if (hasTicket) { // Nested condition to check if they have a ticket\n",
" console.log(\"You can attend the concert.\");\n",
" } else {\n",
" console.log(\"You need a ticket to attend the concert.\");\n",
" }\n",
"} else {\n",
" console.log(\"You do not meet the age requirement for this concert.\");\n",
"}\n",
"```\n",
"\n",
"---\n",
"\n",
"1. The code below checks if you can cook a meal at home. \n",
"2. It uses the presence of hunger, and ingredients, to determine if cooking a meal is possible at home.\n",
"3. It uses booleans in the code\n"
]
},
{
Expand Down Expand Up @@ -146,8 +170,10 @@
"source": [
"<h3><span style=\"font-family: Ariel; color:#94c4ff\">Popcorn Hack 2</span></h3>\n",
"\n",
"A: What will you change so that it prints \"You aren't hungry. Maybe meal-prep for later if you had ingredients.\" ?\n",
"B: What will you change so that it prints \"You can make a cheese sandwich at home.\" ?"
"1. Open two new code cells and set them to javascript\n",
"2. Copy the code example from above javascript cell into both the new code cells \n",
"3. Change the first new code cell to print \"You aren't hungry. Maybe meal-prep for later if you had ingredients.\" \n",
"4. Change the second new code cell to print \"You can make a cheese sandwich at home.\" "
]
}
],
Expand Down

0 comments on commit 5f052c6

Please sign in to comment.