-
Is the
!operator a unary operator, or binary operator? -
Evaluate each of the following expressions first on a whiteboard, and then in a console:
!(2 >= 2) !(4 === 4) !(5 !== 5)
-
Evaluate each of the following expressions first on a whiteboard, and then in a console:
1 > 2 || 2 > 2 || 3 > 2 5 < 5 || 75 < 74
-
This guy named "Joe" keeps blacking out at the bar that your function,
bouncer(from the previous module), is in charge of; thus, management has decided to add him to the "blacklist" -- modify thebouncerfunction from the previous section so that the person named "Joe" is rejected with an appropriate message, regardless of his age. -
Write a function called
scoreToGradethat accepts a number as a parameter and returns a string representing a letter grade corresponding to that score.For example, the following grades should be returned given these scores:
- 'A' > 90
- 'B' >= 80
- 'C' >= 70
- 'D' >= 60
- 'F' < 60
function scoreToGrade(score) { // TODO: your code here } scoreToGrade(95); // => 'A' scoreToGrade(72); // => 'C'
-
Modify the
scoreToGradefunction so that it returns'INVALID SCORE'if the score is greater than100or less than0.
-
Think of at least three activities that you enjoy doing outdoors and the range of temperatures and weather patterns (e.g sunny, windy, snowy, rainy, etc.) that are best for these activities. Write a function
whatToDoOutsidethat accepts a temperature and condition as parameters and outputs a string of the format: "The weather is ideal for: ACTIVITY" (where ACTIVITY is an actual activity). Make sure to include anelsethat indicates what should be done if the conditions do not match any activities. If you're short on inspiration, here are some ideas:- Snow Sports: snowboarding, skiing
- Water Sports: surfing, sailing, paddle boarding, swimming
- Team Sports: basketball, baseball, football (American or everywhere else), etc.
-
The
guessMyNumberfunction from the Booleans & Conditionals module (More Practice section) accepts a guessnand checks it against a random number from0to5-- if the guessnis greater than5, output a different message indicating that the guess is out of bounds.- NOTE: It will be helpful to first write a
randIntfunction that accepts a numbernand computes a random integer from0ton; then, you can use this function inguessMyNumber.
- NOTE: It will be helpful to first write a
-
Modify the
scoreToGradefunction so that it returns'A+/A-'for scores of 98-100/90-92 respectively. Apply the same logic for all other letter grades.
-
The bar that employs our
bouncerfunction has decided to do live music on Friday and Saturday nights, and will be admitting those that are over 18 to the bar on those nights; the catch however, is that all who are 21 or older will need to be given a wristband to distinguish them from the minors. Modify yourbouncerfunction to handle this situation. -
You should have noticed a large amount of repetitive code when modifying
scoreToGradeto accommodate+or-grades. When we do lots of repetitive things, that's a clear signal that there's a better way. Write a helper functionletterGradethat accepts two arguments, letter and score, and works as follows:function letterGrade(letter, score) { // your code here } // These are examples of what a *working* function would output. letterGrade('A', 95); // => 'A' letterGrade('A', 91); // => 'A-' letterGrade('B', 88); // => 'B+' letterGrade('monkey', 160); // => 'monkey-'
Finally, use
letterGradeto remove the repetition inscoreToGrade. -
It turns out that we can write logical and and logical or in terms of each other and logical not using De Morgan's Laws.
- Write a function
orthat works like||, but only uses!and&&. - Write a function
andthat works like&&, but only uses!and||.
- Write a function