Skip to content

Instantly share code, notes, and snippets.

@RayRedGoose
Last active July 17, 2019 16:44
Show Gist options
  • Save RayRedGoose/dd2dbc1c45189bdf3021b0ede53d41d6 to your computer and use it in GitHub Desktop.
Save RayRedGoose/dd2dbc1c45189bdf3021b0ede53d41d6 to your computer and use it in GitHub Desktop.

Tracking Technical Module 0 Capstone Progress

Day 5

Reading Chapter 2 (Statements, Variables, Data Types, & Arrays) from JavaScript & jQuery: Interactive Front-End Web Development

  1. How do you declare a variable. What does the equals sign really mean in JavaScript? What is it called in JavaScript?

    Variables stores the bits of information a script needs to do its job. The equals sign is assignment operators that asigns a value to the variable.

  2. There are three big data types in JavaScript: numbers, strings, and booleans. Describe what each of them are.

    The numeric data type handles numbers.

    The strings data type consists of letters and other characters.

    Boolean data types can have one of two values: true or false.

  3. What are the six rules for naming variables? What are a few JavaScript reserved words that you should avoid using for variable names?

    • The name must begin with a letter, dollar sign ($),or an underscore (_). It must not start with a number.
    • The name can contain letters, numbers, dollar sign ($), or an underscore (_). Note that you must not use a dash(-) or a period (.) in a variable name.
    • You cannot use keywords or reserved words. Keywords are special words that tell the interpreter to do something. Reserved words are ones that may be used in a future version of JavaScript.
    • All variables are case sensitive, so score and Score would be different variable names, but it is bad practice to create two variables that have the same name using different cases.
    • Use a name that describes the kind of information that the variable stores.
    • If your variable name is made up of more than one word, use a capital letter for the first letter of every word after the first word.
  4. How can an array be useful when dealing with multiple related values? How do you access/change a value in an array?

    Arrays are especially helpful when you do not know how many items a list will contain because, when you create the array, you do not need to specify how many values it will hold.

    To access a value from an array, after the array name you specify the index number for that value inside square brackets.

    You can change the value of an item an array by selecting it and assigning it a new value just as you would any other variable (using the equals sign and the new value for that item).

  5. What is the difference between an expression and a statement?

    A statement is an instruction to perform a specific action.

    An expression produces a value and can be written wherever a value is expected.

  6. What are three types of operators and how are they used?

    Assignment operators assign a value to a variable.

    Arithmetic operators perform basic math.

    String operators combine two string.

Practice task

For each task listed below, enter it in the console:

  • 25

  • "this is my string" (notice the output's color difference between a number and a string)

  • var myNewString = "Hello Turing!";

  • myNewString Before you hit Enter, what do you expect to see in the console?

    "Hello Turing!"

  • var myNum = 9;

  • myNum Before you hit Enter, what do you expect to see in the console?

    9

  • var anotherString = "How are You?"

  • "Connect" + " " + "these" + " " + "strings." What happened? This is called string concatenation. Notice the strings with spaces.

    United to one string

  • myNewString + anotherString This is also string concatenation using variables.

    "Hello Turing! How are You?

  • 5 > 3 returns a boolean value of true. How could you change this expression to return false?

    5 < 3 returns a boolean value of false

  • "2" === 2 and "2" == 2 Why does one of those expressions return true and one return false?

    Strict equality (===) means values which we are comparing must have the same type. This means "2" (string type) will not be equal to 2 (number type) ("2"===2 it will return false). Type converting equality (==) means automatically it will covert the variable to value irrespective of data type; either it is a string or a number.

  • if (8 < 9) {console.log("Hey!")} Before you enter this code in the console, what do you think will happen? Will it log Hey to the console?

    It will show "hey", because 8 < 9 is true.

  • Write an if/else statement where the code in the else block is executed. For example: if (3 < 1){console.log("if block")} else {console.log("else block")}

    if (10 > 5) { console.log("10 more than 5"); } else { console.log("10 less than 5"); }
    
    
  • Use the console to solve problems.

    1. The Fortune Teller
    var numberOfChildren = 2;
    var partnerName = 'David';
    var geoLocation = 'Miami';
    var jobTitle = 'dentist';
    
    var predict = "You will be a " + jobTitle + " in " + geoLocation + ", and married to " + partnerName + " with " + numberOfChildren + " kids.";
    
    console.log(predict);
    
    
    1. The Age Calculator
    var currentYear = 2019;
    var birthYear = 1990;
    
    var withBirthday = currentYear - birthYear;
    var NoBirthday = withBirthday - 1;
    
    var possibleAge = "You are either " + NoBirthday + " or " + withBirthday + ".";
    
    console.log(possibleAge);
    
    
    1. The Lifetime Supply Calculator
    var currentAge = 28;
    var maximumAge = 91;
    var yearLeft = maximumAge - currentAge;
    var estimatedAmount = 104;
    
    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 + ".";
    
    console.log(message);
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment