Skip to content

Instantly share code, notes, and snippets.

@poozipotti
Last active January 19, 2021 23:01
Show Gist options
  • Save poozipotti/419ad7f038c70a76e74ece0f5ccfb86c to your computer and use it in GitHub Desktop.
Save poozipotti/419ad7f038c70a76e74ece0f5ccfb86c to your computer and use it in GitHub Desktop.
assignments for nataly

Class Assignment 3: Conditionals Practice!

Make sure to nest your JQuery library into the tag.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

For each of the test questions, use conditionals to check whether the correct answer was provided by the user. The click handlers for each question have been provided for you (except for the last question). Go through each question, and do the following:

  1. English : Write an if/else conditional statement to check if the value of the variable englishInput is correct (the answer should be Mon).

  2. Social Studies : Write an if/else conditional statement to check if the value of the variable ssInput is correct (the answer should be Albany). If it is correct, use .text() to display a message in the div with the ID ssMessage. (Hint: refer to the code in the previous question)

  3. Math : Write an if/else conditional statement to check if the value of the variable mathInput is correct (the answer should be the number 30). If it is correct, use .text() to display a message in the div with the ID mathMessage.

  4. Science: Write a click handler for the button in the science question (refer to the HTML for the ID of the button). Create a variable that stores the value of the input in the science question. Then write an if/else conditional statement to check if the value of the variable you created is the correct answer (the answer is solid). If it is correct, use .text() to display a message in the div with the ID scienceMessage. (Hint: refer to the code in the previous questions for guidance)

If you finish early: When a student gets the answer right, make it so their answer turns green. If they get it wrong, make their answer turn red. Also, add some images to each of the subject lines and change the background.

*Don't forget to hit submit when you're finished!

Temperature Converter: Using Math Functions JavaScript has a built-in tool that can generate a random number between 0 and 1. This tool is called a method. We'll talk about methods later in the class. For now, know if you type Math.random(), you'll get a random number between 0 and 1. Using this tool, update your Fahrenheit to Celsius temperature conversion program to do the following:

  • Instead of inputting a value for the Fahrenheit temp, use Math.random() to generate a random temp between 0 and 100
  • Have the program output: "It is NN°F today. That's NN°C."

The Calculator: Work on the following:

  • Write a function called squareNumber that will take one argument (a number), square that number, and return the result. It should also log a string like "The result of squaring the number 3 is 9."
  • Write a function called halfNumber that will take one argument (a number), divide it by 2, and return the result. It should also log a string like "Half of 5 is 2.5.".
  • Write a function called percentOf that will take two numbers, figure out what percent the first number represents of the second number, and return the result. It should also log a string like "2 is 50% of 4."
  • Write a function called areaOfCircle that will take one argument (the radius), calculate the area based on that, and return the result. It should also log a string like "The area for a circle with radius 2 is 12.566370614359172."
  • Bonus: Round the result so there are only two digits after the decimal.
  • Write a function that will take one argument (a number) and perform the following operations, using the functions you wrote earlier:
    • Take half of the number and store the result.
    • Square the result of #1 and store that result.
    • Calculate the area of a circle with the result of #2 as the radius.
    • Calculate what percentage that area is of the squared result (#3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment