New comment for each day of the capstone
-
-
Save monstaro/c36e2385be240f96c007204270f491e0 to your computer and use it in GitHub Desktop.
To declare a variable, type the keyword var
and then whatever variable you are using, for example, quantity
The equals sign is an assignment operator. It assigns a value to the variable, for example, if your variable name and value is a quantity of 3, you could type quantity = 3;
and the equals sign assigns the value to the name.
Strings: Strings consist of letters and other characters such as symbols & punctuation. They are enclosed in a pair of single or double quotes, and are usually used to add new content into a page.
Numbers: Probably the most self-explanatory. This data type stores numbers, including positive and negative numbers, as well as fractional numbers/decimals.
Booleans: Booleans return one of two values: true or false. Possibly the most complex of the three data types (at least at first) it can help return results to a user such as color preference of a car or location information.
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 cannot start with a number. It must begin with a letter, dollar $ign, or under_score.
- The rest of the name can contain anything listed above, with the addition of numbers as well. Do not use a dash - or a period . in a variable name.
- Cannot used a reserved word or keyword. There are full lists available for reserved words in JavaScript. An example would be
var
because it is already a keyword, so you cannot name a variable a keyword that already exists. - Variables are case sensitive. Always use consist casing when naming variables, and it is good practice not to create two variables with the same word but different casing.
- Use a relavent name when naming variables. For example,
hairColor
eyeColor
instead ofcharacteristicA
andcharacteristicB
- If the variable name is more than one word, you want to keep the first word entirely lowercase, and for every following word, capitalize the first letter.
forExampleThis
. This is called camelcase. You can also use underscores, but not dashes.
How can an array be useful when dealing with multiple related values? How do you access/change a value in an array?
Arrays are useful when you are creating a list and you don't know how many items it will contain. This way, you don't have to create enough variables for a long list. To access a value in an array, you type array_name[array_value]
or put into context, colors[2]
using the example from the book. To change that value, simply add an equals sign and new value in quotes. The full statement would look like this: `array_name[array_value] = 'new value'
What is the difference between an expression and a statement?
A statement simply is a line of instructions, like `array_name[array_value] = 'new value'
An expression can either assign a value to a variable, or use multiple variables to return a single variable.
Basically, an expression is meant to return a single value from one or multiple values, but a statement is more like an instruction.
Three types of operators covered in Chapter 2 are assignment, arithmetic and string operators.
Assignment Operators assign a value to a variable, ex. size = 'large'
Arithmetic Operators perform basic math. ex. hoursPerMonth = 40 * 4;
String Operators can combine two strings 'Today is' + 'September 24th';
An alt attribute provides information about the image if a user cannot see it. This applies especially for search engines and users with screen readers.
An image element is inline if it is within a block level element. It will not start on a new line. An image element is block if it is placed before another block element, such as
<p>
or<h1>
What are the benefits of jpg or png image file formats? .jpg formats are suited for images with many different colors such as photographs. .png and .gif are better suited for images with few colors that cover larger areas, such as logos. .png photos can also be saved to feature transparency on rounded edges and semi-opaque colors.
Chapter 16
Indicating image size in CSS is important because it helps the webpage load more smoothly. The code typically loads before the images, so specifying image size 'reserves' the space for them on the website so the images won't move all the words around when it loads.
An image sprite is when a website has multiple uses of the same image, which allows for the page to load faster.