Lesson 2: Writing Simple Scripts Flashcards
What is each script known as?
A statement.
What should each statement end with?
A semi-colon ;
What are comments used for?
To explain what your code does.
Show a single line comment:
// single line comment
Show a multiple line comment:
/* multiple line comment */
What data types are there?
- Number : 3-5
- Boolean: true/false
- Undefined
- Null
What are variables used for?
To store information temporarily in order to complete certain tasks.
Declare a variable:
- vair quantity; // prior ES6
- let price; // variable
- const ratio; // constant
What type are Strings in JavaScript?
Primitive.
Use a string constructor to make a new string:
let str = new String(‘Hello’);
What does ‘Escaping’ mean?
Making a regular char after \ special and making a special char after \ literal.
Show escaping:
let question = ‘What/’s your name?’;
What does the string operator + symbol do?
Joins strings on either side of it.
Show concatenating strings:
let greeting = 'Hello'; let name = 'Bob' let message = greeting + name;
What are events?
The browser’s way of saying “Hey, this happened.”
What are Arithmetic Operations?
Addition, subtraction, multiplication and division.
Show an Arithmetic Operation:
var theSum = 4 + 3;
Show an Arithmetic Operation using variable names:
var productCount = 2; var subtotal = 14.98; var shipping = 2.75; var total = subtotal + shipping;
Show an example of Combining Operators:
price = price * uplift; price*= uplift
How to convert Celsius to Fahrenheit?:
var hTemp = cTemp*9/5 + 32;
Write a code snippet converting Celsius to Fahrenheit:
var hTemp = cTemp *9/5 + 32;
document. write(“Temp in C: + cTemp + “degrees<br></br>”);
document. write(Temp in F + hTemp + “degrees”);
What are three event handlers?
onClick, onMouseOver and onMouseOut
What can the onClick event handler do?
Be applied to nearly all HTML elements.
Show an example of an onClick event handler:
What do the onMouseOver and onMouseOut event handlers used for?
When you want to detect where the mouse pointer is on the screen with a reference to a page element.
Show an example of onMouseOver:
<img></img>