Skip to content

Instantly share code, notes, and snippets.

@RayRedGoose
Last active July 17, 2019 16:45
Show Gist options
  • Select an option

  • Save RayRedGoose/63bc4076c5c9b36d5fd7895af7933763 to your computer and use it in GitHub Desktop.

Select an option

Save RayRedGoose/63bc4076c5c9b36d5fd7895af7933763 to your computer and use it in GitHub Desktop.

Tracking Technical Module 0 Capstone Progress

Day 6

Reading part of Chapter 3 (Functions & Scope), pages 85-99 from JavaScript & jQuery: Interactive Front-End Web Development

  1. If we have a function defined as function sayHello(){console.log("Hello!")}, what is the difference between entering sayHello and sayHello() in the console?

    sayHello() is correct function name. In round brackets parameters of the function is placed. If the function doesn't have any parameter name of the function is typed with round brackets without any signs inside it.

  2. What is the difference between function parameters and arguments?

    Parameter is variable in the declaration of function.

    Argument is the actual value of this variable that gets passed to function.

  3. What is the keyword return used for?

    The keyword return is used to return a value to the code that called the function.

  4. How are local variables better than global variables? Are there instances you can think of where you might want to use a variable that is globally scoped over local?

    When a variable is created inside a function using the var keyword, it can only be used in that function. It is called a local variable or function-level variable.

    If you create a variable outside of a function, then it can be used anywhere within the script. It is called a global variable.

    Global variables are stored in memory for as long as the web page is loaded into the web browser. This means they take up more memory than local variables, and it also increases the risk of naming conflicts. For these reasons, you should use local variables wherever possible.

Practice tasks

Java Script

  • Work through problems in the console about functions.

    1. The Fortune Teller
    function tellFortune(numberOfChildren, partnerName, geoLocation, jobTitle) {
      var predict = "You will be a " + jobTitle + " in " + geoLocation + ", and married to " + partnerName + " with " + numberOfChildren + " kids.";
    
      return predict;
    }
    
    tellFortune(2, "Joe", "San Diego", "teller");
    
    
    1. The Age Calculator
    function calculateAge(birthYear, currentYear) {
    
       var withBirthday = currentYear - birthYear;
       var NoBirthday = withBirthday - 1;
    
       var possibleAge = "You are either " + NoBirthday + " or " + withBirthday + ".";
    
       return possibleAge;
    }
    
    var dateToday = new Date();
    var currentYear = dateToday.getFullYear();
    
    calculateAge(1993, currentYear);
    
    
    1. The Lifetime Supply Calculator
    function calculateSupply(currentAge, estimatedAmount) {
     var maximumAge = 90;
     var yearLeft = maximumAge - currentAge;
    
     var perYear = estimatedAmount * 365;
     var perFullYear = estimatedAmount * 366;
     var numberFullYear = yearLeft / 4;
     var number365Year = yearLeft - numberFullYear;
    
     var totalEat = (numberFullYear * perFullYear) + (number365Year * perYear);
    
     var message = "You will need " + totalEat + " to last you until the ripe old age of " + maximumAge + ".";
    
     return message;
    }
    
    calculateSupply(24, 81);
    
  • Practice through some JavaScript basics exercises on w3resource and check your code against their solutions.

Command Line Crash Course

  • Do all of the exercises: 1-15

Git and GitHub

  • We want you to git really good at Git and Github, please read through the the Git handbook from GitHub here.

  • Also, this blog has references to commands and their meaning that might be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment