Skip to content

Latest commit

 

History

History

project-javascript-e1-scope

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Project JavaScript E1 SCOPE

  • Blocks and Scope
  • Global Scope
  • Block Scope
  • Scope Pollution
  • Practice Good Scoping

If you are not familier with them please download Learn JavaScript eBook at https://codingwithbasir.com/learn-javascript

Project Title: Color Picker

  1. Create a html file with your name like john.html
  2. Add current code to that file:
<!DOCTYPE html>
<html>
  <body>
    <script>
      // your code here
    </script>
  </body>
</html>
  1. Define a global variable named color with const and set it to blue

  2. Declare a function named logColor1 without parameter and log color varibale into console.

  3. Declare a function named logColor2 with a parameter named color and log color varibale into console.

  4. Call function logColor2 with 'red' as argument and check the result.

  5. Declare a function named logColor3 with a parameter named color and log color varibale into console.

  6. In this function, add an if statement before console.log that check color is green. If it is green use let to define a variable named color and set it light green, then console.log(color)

  7. Call function logColor3 with 'green' as argument and check the result.

  8. Analyze and discuss the behaviour of scoping in all steps.