Guide: Javascript Introduction - Conditionals
Description
👉 This guide is part of the Javascript Introduction Guides. Please follow the order:
- Fundamentals & Data Types
- Conditionals
- Loops & Iterators
- Functions
- ES6
Conditionals are ways that a programming language has to well… condition a certain action. For example: If hungry, then eat. There's a little more detail to it and that's what you will explore in this Guide.
Knowledge
- Understand what conditional statements are
Skills
- Be able to execute conditional statements in Javascript
Topics
- Conditionals
- If/Else
- Logical operators (!, ||, &&)
- Ternary operator
- Switch
- break
- If/Else
Action Points
- Read up on conditionals to understand what tools are available
- Exercise all concepts in Repl.it or similar
Deliverable: Exercise solution
- Submit:
- Repl.it Project URL (Javascript Repl)
- Add comments for each relevant code block
- Exercise description:
- Download the randomized data: https://api.mockaroo.com/api/6352abc0?count=5&key=632d7f80
- Create a Javascript file that describes the data using the appropriate data types
- In the same file, making sure each person is represented by an object in an array:
- Answer the following questions using if statements and console.log()
- Is the first person older than the last person?
- Does the 2nd person have the same amount of kids as the 3rd?
- Create a statement that checks if the 1st person and the 4th person in the array both know how to program. If yes, output “Yay!”, if not output “LMGTFY”.
- Create a statement that checks the 2nd person in the array for their nationality. If the person’s country is Iceland, output “Hæ”, if he/she is from Spain output “Hola”, if he/she is from Korea output “여보세요”). If the country is none of the above, output “Hello”. Tip: a switch statement might be a good fit for this task.
- Use a ternary operator to output if the 2nd person’s name is longer than 5 characters.
- Answer the following questions using if statements and console.log()
- Use a title/explanation for each part
- Showing results via DOM manipulation is not required but is welcome and would replace the use of console.log()