Week 6 - JavaScript (Part 2)
Week 6 - JavaScript (Part 2)
Sean Preston
What you’ll learn today…
1. Continue to learn the JavaScript programming language.
• For example, we can convert the string “50” into an integer by using:
parseInt(‘50’);
• We can also use the % modulus operator. This operator divides the
first value by the second and returns the remainder. This can be used
to check if a value is odd or even. When divided by two, if 0 remains,
the value is even. If 1 remains, the value is odd.
const isOdd = 200 % 2; // Will return 1 if odd, 0 if even
JavaScript Operations – Increment
• We can also use -- to decrement a value and ++ to increment a value.
• === Equality
• !== Inequality
•> Greater than
•< Less than
• >= Greater than or equal to
• <= Less than or equal to
JavaScript Operations – Comparisons
• We can also use ==. However, it’s often not advised.
{“name”:”Bob”,”type”:”cat”,”age”:”8”}
JSON Activity – 15 min
• Visit https://api.tvmaze.com/search/shows?q=simpsons
• Install the “JSON Viewer” extension for Chrome. Then, re-open the
above URL.
• We can then use the .then() and .catch() methods to execute code on the
fetch being resolved (i.e. successful) or rejected (i.e. error).
• Often the data being returned is in JSON and will need to be converted!
Once you have
completed the activities
in a lesson you should
work on your assignment
Activities