{ "cells": [ { "cell_type": "raw", "id": "8bc5a172", "metadata": { "vscode": { "languageId": "raw" } }, "source": [ "---\n", "layout: post\n", "toc: True\n", "breadcrumb: True\n", "title: JS Variables Homework\n", "description: These are the homework problems and popcorn hacks.\n", "permalink: /csse/javascript/fundamentals/variables-hw\n", "author: Samarth H, Anish G, Krish K, Pranay K\n", "---\n" ] }, { "cell_type": "markdown", "id": "96e1f102", "metadata": {}, "source": [ "\n", "\n", "Presented by the\n", "

TINKERERS

\n", "\n", "
\n", "\n", "#
Popcorn Hack 1 🍿😈
\n", "\n", "Let's start diving into some of the questions. \n", "\n", "## Instructions\n", "\n", "Below instructions refer to this code cell:" ] }, { "cell_type": "code", "execution_count": 7, "id": "79b0d5df", "metadata": { "vscode": { "languageId": "html" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "

Popcorn Hack 1 Output

\n", "
\n", "\n", " \n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "\n", "\n", "\n", "

Popcorn Hack 1 Output

\n", "
\n", "\n", " \n", "\n", "\n" ] }, { "cell_type": "markdown", "id": "63fb0920", "metadata": {}, "source": [ "Now, do the below with this code.\n", "\n", "1. Adjust var declarations, names, values, etc. Mess around with it and observe any changes/errors. \n", "2. Think and/or discuss with your table: what changes did you notice?\n", "\n", "Now let's make some changes :)\n", "\n", "3. Uncomment the line saying `age = 2;` and look at your console. What do you notice?\n", "\n", "4. Add a new variable called `hobby` with the value of \"painting\" and update the DOM output and console output to say: \n", " \"[NAME] is [AGE] years old, lives in [CITY], and loves [HOBBY]\"\n", "\n", "5. There's a keyword called `typeof` in JavaScript. Use this keyword to also display the data types of the variables.\n", " Example: `typeof \"John\"` gives `\"string\"` and `typeof 3.14` gives `\"number\"`" ] }, { "cell_type": "markdown", "id": "9c21d1a0", "metadata": {}, "source": [ "
\n", "\n", "#
Popcorn Hack 2 🍿😈
\n", "\n", "Follow the below instructions.\n", "\n", "1. Go to the code cell below this text.\n", "2. Using the correct JS variable naming convention, declare a Magic Number variable with the value returned by `input.value` to get a user response.\n", "3. Convert it to a Number data type using Number(). Example: `let x = Number(x);` turns x into a Number. This is because prompt() always returns Strings.\n", "4. Create variables `doubled`, `squared`, and `tripled` that contain the doubled, squared, and tripled values of the magic number.\n", "5. Display the results in DOM and the console by changing output.innerText and using console.log()." ] }, { "cell_type": "code", "execution_count": 9, "id": "071fb4db", "metadata": { "vscode": { "languageId": "html" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "

Click the button after entering your magic number!

\n", "\n", " \n", " \n", "\n", "
Your results will appear here.
\n", "\n", " \n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "\n", "\n", "\n", "\n", "

Click the button after entering your magic number!

\n", "\n", " \n", " \n", "\n", "
Your results will appear here.
\n", "\n", " \n", "\n", "\n", "" ] }, { "cell_type": "markdown", "id": "299f5792", "metadata": {}, "source": [ "\n", "
\n", "\n", "# Variables Homework (Show what you know!)\n", "\n", "### Homework Problems: Understanding JavaScript Variables \n", "\n", "There is a code block below the image saying \"Have Fun!\" Write your code in there.\n", "\n", "### Part A - Creating Variables\n", "\n", "1. Create a variable called `name` and store your first name in it. Print it in the console and to DOM.\n", "\n", "\n", "2. Create two variables `age` and `city`. Print them in a single sentence like:\n", " - \"I am 15 years old and I live in New York.\"\n", "\n", "\n", "3. Create a variable `isStudent` (true/false). Print it.\n", "\n", "### Part B – Numbers & Strings\n", "\n", "\n", "4. Create two number variables num1 = 10 and num2 = 5. Print their sum, difference, product, and quotient.\n", "\n", "\n", "1. Make a variable `favoriteFood` and print:\n", " My favorite food is ____.\"\n", "\n", "### Part C – Practice Problems\n", "\n", "\n", "6. Swap the values of two variables: x = 7 and y = 3.\n", "\n", "\n", "7. Create a variable `fullName` by joining two strings: \"FirstName\" and \"LastName\".\n", "\n", "\n", "8. Convert temperature C = 25 into Fahrenheit using F = (C * 9/5) + 32.\n", "\n", "\n", "9. Create a variable score = 85.\n", " - Print \"Pass\" if score >= 50, else \"Fail\".\n", "\n", "\n", "\n", "10. Write a program that asks for your name and age (use prompt)\n", " and prints: \"Hello , you are years old.\"\n", "\n", "11. Make a project that uses 5 variables to run. It can do anything yuou want, have fun and good luck!\n", "\n", "Extra credit (optional): \n", " Instead of hard coding the variable for number 9 to 85, make the variable a random number from 1-100.\n", "\n", "![An image of have fun](https://as2.ftcdn.net/jpg/05/52/30/29/1000_F_552302940_Nct9zn3a6us0igBJqlkDQzQnbM4LLvmS.jpg \"An image of have fun\")\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "5d1aac40", "metadata": { "vscode": { "languageId": "html" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "

Homework Output

\n", "
\n", "\n", " \n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "\n", "\n", "\n", "\n", "

Homework Output

\n", "
\n", "\n", " \n", "\n", "" ] }, { "cell_type": "markdown", "id": "c45bc843", "metadata": {}, "source": [ "# Submission\n", "\n", "You will submit the link to your homework on a web page in the below form. \n", "If you are unable to get your homework accessible from the website, you can upload this Jupyter notebook to the form.\n", "\n", "**IMPORTANT: If uploading, please name this Jupyter notebook in this format: [FirstName][LastName]_vars_hw.ipynb**\n", "Example: SamarthHande_hw.ipynb\n", "\n", "\n", "\n", "Requirements for homework:\n", "1. Parts A, B, and C should be completed. You will get .3 points for each question completed.\n", "2. Up to 0.03 extra points will be given to code that demonstrates exceptional creativity and comprehension." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6" } }, "nbformat": 4, "nbformat_minor": 5 }