Class 7 - Programming with JavaScript

Lab 7 - Programming with JavaScript
Requirements
- Use functions to improve the clarity and readability of your code.
- Wrap related steps into a single function. Be sure you are properly defining the function, calling it, and getting the return value you expect.
- Can you see how you might use just a single
<script> tag with a src attribute to access your JS, and then specific function calls throughout the rest of your page?
- Add a check to the user input you are getting, to see if the initial user input is an acceptable value. If not, present the user with an error message and a second chance to enter a proper value.
Written Class Notes
function askName (){} let userName = prompt () console.log(userName) in HTML use <script> askName()</script> This last part is invoking in HTML
- Whatever declared in one function only exists within that function. Add return (function name) and assign the function with let at the beginning.
function name (parameter){logic}
Read 7 - Programming with JavaScript Reflection and Discussion
Resources Link/Pages
- MDN Control Flow
- Functions
- They are blocks of code that do specific tasks
- Invoke: Executes code inside function
return: function stops executing
- Operators
- Types of operators: Arithmetic Operators, Assignment Operators, Comparison Operators, String Operators, Logical Operators, Bitwise Operators, Ternary Operators, Type Operators
- Arithmetic perform arithmetic on numnbers (+, -, *, /)
- Assignment adds value to variable (+=)
- Comparison (==, ===, !=)
- Adding a number and a string will return a string and combine two value together (4+’2’=’42’)
- Expressions and Operators
- Functions
Answer
- What is
control flow?
- The order in which computer execute a script, looking from start to finish but also how the script structure is as it can affect order of execution.
- What is a JavaScript
function?
- Blocks of code that do specific tasks
- What does it mean to
invoke - or call - a function?
- Calling the function will tell the code inside the function when to execute it.
- What are the parenthesis
() for when you define a function?
- Its to specify the parameters that the function accepts