Unit 1 Flashcards
How To: Open a box that says Hello, world!
alert (“Hello,world.”);
What Are The Steps in Program Development?
- Define the problem
- Outline the solution
- Develop the outline into an algorithm
- Test the algorithm for correctness
- Code the algorithm into a specific programing language working in “versions”
- Run the latest “version” of the program on the computer
- Document and maintain the program
How do you define the problem?
- Input variable list
- processing checklist
- output variable list
How do you Outline the Solution?
- the major processing steps
- the major subtasks
- the user interface
- the major control structures
- the major variables and record structures
- the mainline logic
What is the unit of indentation for JavaScript?
Four Spaces
If a line of code is too long to fit on one line of the text editor, what unit of indentation must the continuation of the line be?
Eight Spaces
What is the maximum number of characters to use on a JavaScript line?
80 Characters
What are the comments that we need to use in this class?
- Our Name, Section and email at the top of our labs.
- A comment line at the start of each section within a program. These section comment lines must start with a verb. (Describing an action)
What are Semicolons used for in JavaScript?
To terminate a statement.
var firstName="Fred"; document.write(firstName);
Every Simple Statement must end with a semicolon, true or false?
True
Every simple statement must be on its own line, true or false?
True
When should you use blank lines?
- After each section of your program.
- Most operators must have a space above and below
- A space should follow every comma “,”
// Operator spacing
var firstName = "Fred"; var errorCount = 0;
errorCount += 3; enteredNumbersSum = numberOne + numberTwo;
// Note: The three exceptions to this rule are for the dot "." , // the "++", and the "--" operators.
loopCounter++; // no space around the ++ loopCounter--; // no space around the -- document.write("Hi Parent"); // no space around the dot
What is JavaScript?
- JavaScript is an interpreted programing language.
2. There is a full computer program inside each browser that reads your JavaScript code and runs the code.
What is an “Interpreter”?
The full program within each browser that reads and runs the JavaScript code.
What are the three rules that we are concerned with in this class?
- Syntax
- Convention
- Style
What is the rule of syntax?
If a computer programing language enforces a rule then we call that rule “syntax”. This is the strongest level of rule. If you break this rule, the program will not run.
What rule is this?
If a computer programing language enforces a rule, this is the strongest level of rule. If you break this rule, the program will not run.
The rule of Syntax.
What is the rule of Convention?
If most users of a programing language all over the world do something the exact same way, it is called a “Convention”. Although the JavaScript language itself doesn’t care about these rules, if everyone is using them, there is a good reason for it. A professional follows convention.
What rule is this?
Something that users all over the world do the same. Although the JavaScript language does not care, there is usually a good reason for this and a professional will follow it.
The rule of Convention.
What is the rule of Style?
There are many ways of structuring your code. The main thing is that you pick a method and stick with it. Be consistent.
What rule is this?
There are many ways of structuring your code. The main thing is that you pick a method and stick with it. Be consistent.
The rule of Style.
Is JavaScript case sensitive?
yes.
True or False
JavaScript is not case sensitive.
False. JavaScript is case sensitive.
What is White Space in JavaScript?
- Space
- Tab
- Carriage Return (officially called the “line terminator”
What does RAM stand for?
Random Access Memory
What Three things do computers do from our perspective?
- They get data into the program
- They process the data
- They output the data
What is RAM, Random Access Memory?
RAM is one long linear chain of bits. And a bit is a very simple thing, it’s just a 0 or a 1.
Think of each mark on the tape measure as a single bit.
Data is just a collection of bits in a known spot.
Say, starting at 5” on the tape measure and going for 10 marks.
What is a variable?
Data within a program is stored in variables. From a software perspective, a variable is a container that holds references to data.
What is a container that holds references to data.
A Variable
How many types of JavaScript statement are there?
2 types of JavaScript statements.
- A simple Statement
- A compound statement
What is a simple JavaScript statement?
A simple statement is simple:
x = 4;
What is a compound statement?
A compound statement combines multiple levels of logic. An if/the/else conditional is a good example:
if (something == 1) { //Some Code Here } else { //Some other code here }
Triue or False, there are five JavaScript statement types.
False. There are Two Types of JavaScript statements.
True or False. A Compound statement is a simple statement.
False. A compound statements combines multiple levels of logic. Example would be an if then else statement.
True or False, certain words are reserved in JavaScript, meaning that you can not use them as Variables, identifiers or constant names within your program.
True.
What are the words that are currently reserved in JavaScript?
break case catch continue debugger default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with
What are the words that start with B that are reserved in JavaScript?
break
What are the words that start with C that are reserved in JavaScript?
Case
Catch
Continue
What are the words that start with D that are reserved in JavaScript?
Debugger
Default
Delete
Do
What are the words that start with F that are reserved in JavaScript?
Finally
For
Function
What are the words that start with I that are reserved in JavaScript?
If
In
Instanceof
What are the words that start with N that are reserved in JavaScript?
New
What are the words that start with R that are reserved in JavaScript?
Return
What are the words that start with S that are reserved in JavaScript?
Switch
What are the words that start with T that are reserved in JavaScript?
This
Throw
Try
Typeof
What are the words that start with V that are reserved in JavaScript?
Var
Void
What are the words that start with W that are reserved in JavaScript?
While
With
How many words are currently reserved in JavaScript?
26
How do you start a variable in JavaScript?
var
Start with the word var. This tells JavaScript to create a variable. The variable will be named by whatever set of characters follows. for example:
var count;
Create a variable named birthday.
var birthday;
Create a variable named count.
var count;
Create a variable named count that has a value in it.
var count = 1;
“ = 1”
A space, an assignment operator, and the number 1
What is a Prompt?
Prompt is a function/method of the window object.
The viewer is prompted to enter something into the text box that displays.
What does the prompt( ) method do?
the program opens a small dialog box on the screen that contains:
- A (usually) short phrase asking the viewer to key in some information
- A text box into which a viewer will key in information
- An OK button for the viewer to click when he/she has keyed in the information
- A cancel button to close the dialog box without keying in anything
Does the prompt() method return something back into the program itself?
Yes. It will return what the viewer keys in.
Does the prompt() method require a variable to catch the returned information?
Yes.
You need to set a variable before the prompt and then use the variable in conjunction with the prompt.
var firstName; //This would be up in the variable section of the program firstName = prompt("Enter your first name");
True or false: The prompt () method always returns a string, even when the viewer keys in just numerals.
True
Break down the following:
document.write(“This is a string”)
- Document refers to the HTML page that contains the JavaScript program
- The period, called the dot, is a way to access things inside of your document.
- The word write is the method of the document object.
Create a variable to print out your name.
var myName = "Jessica Page"; document.write(myName);
Create a variable.
Prompt user for the variable and assign the resulting value to the variable you created.
output the variable to the page
var name;
var name = prompt(“What’s Your Name”);
document.write(name);
Prompt user for var lastName; and assign the resulting value to the variable.
var lastName = prompt(“What’s your last name”);
Output a single space with a document.write()
document.write(“ “);
What are the data types in JavaScript?
- Numbers
- Strings
- Booleans
- Null
- Undefined
- Objects
How many data types are there in JavaScript?
6
- Numbers
- Strings
- Booleans
- Null
- Undefined
- Objects
What three Data Types will we be focusing on this semester?
- Numbers
- Strings
- Booleans
How do you declare a variable that is just a number?
Just declare a variable and put a number in it. Do not type the number with quotes.
var count = 1; var price = 12.99;
Is the following a variable using the Number data type?
var priceString = “12.99”;
No. Because it uses quotes.
A Number Variable is just declaring a variable with a number in it and no quotes.
var priceString = 12.99;
Do we have to tell JavaScript that a variable is a number?
No.
What is a string?
Anything entered into a computer by typing is a string.
When a user is asked to enter a number in a prompt dialog, what data type comes into your program?
A string.
Convert the following to a number.
var price;
price = prompt(“Enter a price.”);
price = Number(price);
What does the Number() function do?
var price;
price = prompt(“Enter a price.”);
price = Number(price)
The number function takes the current string in the variable and converts it to a number if it can. Then our line of code puts the new number back into the price variable.
True or False:
When data enters the program via the prompt() method, the keyed in digits need to be converted to numeric format via the Number() function.
True
True or False:
When data enters the program via the prompt() method, the keyed in digits do not need to be converted to numeric format via the Number() function.
False.
var price;
price = prompt(“Enter a price.”);
price = Number(price)
The entered price (prompt) is a string.
Then it becomes a number, with the number function creating a string and the string being given to the number function.
price = Number(price)
What symbol do we use for addition?
+
What symbol do we use for subtraction?
-
What symbol do we use for multiplication?
*
What symbol do we use for division?
/
True or False:
String are a series of characters surrounded by single or double quotes.
True
What are strings?
Strings are a series of characters surrounded by double or single quotes.
True or False:
If a string is surrounded by double quotes, you can have single quotes inside the string.
True.
True or False:
If a string is surrounded by single quotes, you can have double quotes inside the string.
True
True or False:
You can not have a string with single quotes inside double quotes.
False.
If a string is surrounded by double quotes you can have single quotes inside the string.
True or False:
You can not have a string with double quotes inside single quotes.
False.
If a string is surrounded by double quotes, you can have single quotes inside the string.
What is an escape character?
An escape character is a special character that is added with a preceding “"
How would you add a backspace into a string?
\b
What is \b if in a string?
backspace
How would you add a tab to a string?
\t
What is \t in a string?
tab
What is \n in a string?
newline
How would you add a newline in a string?
\n
How would you add a single quote to a string?
\' example: var output; output = 'Here\'s a single quote.' document.write(output);
What is \f in a string?
Form Feed
What is \r in a string?
Carriage Return
What is \ in a string?
Literal backslash
what is " in a string?
Double Quote
What is ' in a string?
Single quote.
How would you add a carriage return in a string?
\r
How would you add a form field in a string?
\f
How would you add a literal backslash in a string?
\
How would you add a double quote in a string?
"
How would you add a tab to a string?
\t
Example:
var outputOne;
var outputTwo;
outputOne = "one\tTwo\tThree\tFour"; outputTwo = "1\t2\t3\t4\t";
document. write(outputOne);
document. write(“<br></br>”);
document. write(outputTwo);
One Two Three Four
1 2 3 4
What is a property?
A property is a characteristic of an object.
What is the .length property?
it gives the length of a string:
Example:
var whatWillThisBe = “This is a string”.length;
The mystery variable is 16
What is a “Method”?
Method refers to a pre-written program always used in conjunction with an “Object”.
What is the alert() method tied to?
The alert() method is tied to the “window” object.
What refers to a pre-written program that is always used in conjunction with an object?
A method.
True or False:
Method refers to a pre-written program always used in conjunction with an “Object”.
True
True or False:
Methods are not associated with Objects.
False.
A method is a pre-written program that is always associated with an “Object”.
What are three of the simplest “Expressions”?
1. A string. (Text within quotes) alert("Hello World"); 2. A number (No Quotes) alert(123); 3. The Variable Name (No Quotes) alert(firstName);
Can you do mathematical operations in the alert() method?
Yes, but it is not recommended.
How do you convert a string to a number while declaring the variable?
numberOne = Number(prompt (“What is a number?”));