For this exercises we are going to create a file called conditionals.js
. Copy the description of the exercise as a comment into the file and underneath write your JavaScript code.
Note: Remember to fork this repo, clone your copy, modify
conditionals.js
with your answers. Lastlygit add
your changes,git commit
andgit push
-
Write a block of code that checks and logs whether variables are equal or not.
-
Write a block of code that logs which of two number variables is larger.
- Your output should look like this (in this example for the numbers x = 5 and y = 10): 'The greater number of 5 and 10 is 10'
- If the two numbers are equal, log: 'The numbers are equal.'
-
Create a string variable with a language code (e.g. "english", "spanish", "german"). Use an if - else if - else statement to log "Hello, World" in the given language, for at least 3 languages. It should default to logging English.
-
Do question 3 again but this time use a
switch
statement. -
Create a variable numGrade that will contain a numeric grade (out of 100). Use an if - else if ... - else statement to log the corresponding letter grade, either "A", "B", "C", "D", or "F".
-
Create two variables: animalName ('cat', 'dog', etc.) , and numberOfAnimals.
Use an if - else statement to log:
-
the number
-
either in single or plural form. Exp: "5 cats" or "1 dog".
Bonus: Make it handle a few collective nouns like "sheep" and "geese".
-
Write a block of code that logs whether a given number is even or odd.
-
Do question 7 again but use a ternary.
-
Write a block of code that checks and logs whether a given number is positive, negative, or equal to 0.