JavaScript Basics Flashcards

1
Q

What is JavaScript?

A

It’s a programming language that is used in the most versatile way: front-end and back-end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the initials for JavaScript?

A

JS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

According to MDN, what is JavaScript?

A

JavaScript is a programming language that allows you to implement complex features on web pages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where does JavaScript fit in with front end web development?

Cake analogy

A

It’s the third layer of the cake.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does JavaScript do that makes it different
from HTML and CSS?

A

JS is a scripting language that enables you to create
dynamically updating content,
control multimedia,
animate images,
and pretty much everything else.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some things you can create using JavaScript?

A
  • Browser Popups
  • Scrolling Effects
  • Animation
  • Immersive Experiences
  • Games
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some practical applications of JavaScript?

A
  • Maps
  • Gmail
  • Google Tasks
  • Emails
  • Documents
  • Calculations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the JavaScript console?

A

Within developer tools, you can enter and see how your JavaScript program performs. It’s like a JS editor, web based.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the shortcut to open JS console on Windows?

A

Use javascript console

CTRL SHIFT J

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you clear the JS console?

A

Press the grey circle with the diagonal line through it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can you preview JavaScript with the console?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can you debug JavaScript with the console?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the JavaScript console shortcut for mac computers?

A

Press Command + Option + J

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is syntax?

A

It’s a language.

It’s a programming language’s
commands, special words, and punctuation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you run a previous command within the JS console?

A

Previous command up arrow by pressing up key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does alert do?

A

alert opens a dialog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens if you refresh the page?

A

The JS console clears what’s printed on the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Can you clear the console by clicking?

A

Yes

Right click, choose clear console

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What happens if you enter alert(); in the JS console?

A

It creates a popup with that’s missing content.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do JavaScript statements typically end?

A

;

with a semi-colon

alert(“Hello, World!”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does console.log do?

A

Logs or prints the message in the JS console

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What happens if you enter “Hello World” into the console.log?

A

It prints Hello World inside of the JS console, not on the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What does each word within document.write mean?

A

document refers to current web page

write writes text on web page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

If you enter the following code snippet,
what does it do?

A

It prints a temporary headline onto the webpage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do you enter the next line of code,
without running the code?

A

Use shift + return to move to the next
line without running the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

If you write a line of code, then press enter, what happens?

A

It runs the line of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Each line of code is a _____.

A

statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Do statements run in the order in which they appear?

A

Statements run one after the other, from top to bottom.

Each statement needs to complete before
proceeding to the next statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Can you add HTML markup to format text written in JS?

A

Yes

Heading tags, p tags, and other tags can be used within JS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Do you lump your JavaScript code into other HTML or CSS files?

A

No

JavaScript files get their own documents
apart from HTML and CSS files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What does JS do in FEWD?

A

Adds interactivity to a webpage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What role does HTML and CSS play?

A

HTML adds content web page.

CSS add style to a web page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Does every browser have a javascript engine?

A

Yes, all browsers have javascript engine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is a JavaScript engine?

A

A JavaScript engine is program built into the
browser that executes JS code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What does it mean when it’s executing the program?

A

It’s reading the code and processing a segment of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

When a programming language reads and acts upon code it is called ___.

A

Running a program

Same as executing a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

When the browser executes this line of code, then a dialog window appears. Why is this helpful?

A

It communicates what behavior happens
in direct response to a line of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What extension is used to create JavaScript files?

A

.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Do you need to link JS files?

A

Yes, you link JS files to HTML, typically index.html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

How do you initiate the script that connects
the JS file within the index page?

A

See image

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What do images and scripts have in common?

A

src attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What do you put in the quotation marks?

A

The source of the JS is often the path to the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Where is the JS code snippet entered within HTML to connect it to the index.html file?

A

The JS script appears inside of the head tag within index.html file, below the CSS file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Is it possible to add JS directly into HTML?

A

Yes

You use the

 tags to surround the JS</p>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Can you have more than 1 JS file?

A

Yes

So long as they are different files you can have multiple JS files within an HTML document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Where is the most common place for JS file to be placed?

A

Towards the bottom of the page, near the closing body tag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Why would it be placed above the closing body instead of the head area?

A

By placing it near the bottom, it gives the
browser the opportunity to load HTML and
CSS before running any JavaScript on the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Do developers of all skill levels make mistakes?

A

Yes

No one is immune from making programming mistakes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

What are the most common mistakes?

A

Syntax errors relating to punctuation, spacing, or wording are the source of most mistakes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Do browsers provide tools for debugging?

A

Yes, debugging is key to having programs run correctly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

When an error is found, it can tell you what line the error is on. How does this help with debugging?

A

You can go straight to the source of where the error is to troubleshoot effectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

Is JS case sensitive language?

A

Yes, always use the letter-case required by Javascript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What happens if you capitalize alert?

A

It could produce an error message because
alert should be all lowercase letters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What’s wrong with the syntax of this alert?

A

It’s missing “ mark before Hello.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

What’s wrong with the console.log with this syntax?

A

It’s missing a closing parenthesis ) before the ; semi-colon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

What’s wrong with this alert JS syntax?

A

A should be lowercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

What’s wrong with this line of JS?

A

It’s a spelling error.
There should be a w for .write

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Does the JS console show you all errors at once?

A

No

Errors are shown 1 by 1 to fix in numerical order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Most of the time JS needs to work with information that _______.

A

Changes

Dynamic Info > not > Static Info

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

Is custom content for a user on SM dynamic or static?

A

Dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

Is a player’s score static or dynamic?

A

Dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

Is an online shopping cart static or dynamic.

A

eCommerce carts are dynamic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

What is a variable?

A

It is an area where information that changes or
varies, each time a program is run, is stored.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

What is the importance of variables?

A

Variables store information so that later on it
can be used and manipulated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

Why is game score in a game a variable?

A

You can get points.

You can lose points.

You start at zero.

The game score changes dynamically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Variables are like a box because

A

The contents of the box may change, but the box as a container remains the same regardless of the content.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

What is the keyword used to start a variable?

A

var is the keyword that begins the variable syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

What does the keyword var stand for?

A

var stands for variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

Each variable has a ___.

A

name.

Each variable has a name to identify it as a
container of dynamic information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

What role does the = sign play in the syntax of writing a variable?

A

The equal sign = assigns a value to a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

What is an assignment operator?

A

The assignment operator is the
equal sign since it assigns a value to a property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

How do you choose a variable name?

A

A variable name should directly define
what it relates to for maximum clarity and comprehension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

What is a string?

A

A string is a word or phrase
enclosed in single or double quotations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

What happens when this JS snippet runs?

A

It prints the word message out because it’s in quotation marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

When (message) is written out, what happens?

A

It writes the value of the variable message
as hello in the JS console.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

What happens when you write the following
code in the JS console?

A

You are reassigning the value of the message by using the assignment operator = with a new string value in quotation marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

Can you choose any name for a variable?

A

No, there are 20-30 keywords that cannot be used as a variable name as they’re set aside for because the ECMA Script 2015 has reserved these keywords for a future specification.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

If your variable name has two words, what should you do?

A

Capitalize the first letter of the second word

Or Use an underscore between keywords

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

Can you put a number before a variable name?

A

No

Numbers should follow the text name of the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

Should symbols go in the front or back of a variable name?

A

Symbols go in the front of the variable name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

Should you capitalize the second or third
part of a variable name?

A

Yes, capitalization is allowed in the
second or third word of a variable name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

S or Score what’s a more descriptive variable name?

A

Score

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

Which is the better variable name playerScore or n1?

A

playerScore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
84
Q

What’s a better variable name p or pricePerPound?

A

pricePerPound

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
Q

Why is score listed twice in this example?

A

Right of the equation becomes the value of score.

Score increases by multiples of 10.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
86
Q

Can you update a variable with another variable?

A

Yes, it’s quite common to update a variable with a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

What is an addition assignment operator?

A

Shorthand for adding to a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
88
Q

How do you add score + bonus
points together in a game context?

A

You define both variables for score and bonus points.

Then you create a new variable that
adds both variables to calculate the final score.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
89
Q

What are the drawbacks of using the
var keyword to define variables?

A

They can be overwritten.

Overwritten can be difficult to catch.

JavaScript is evolving to improve.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
Q

What two keywords are sometimes used in
place of var within JavaScript?

A

let

const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
91
Q

What’s the format of all variables?

including var, let, const

A

[variable] [variable name] = [value]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

What does const stand for

A

const stands for constant

This means it shouldn’t be overwritten at any point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

Can a const variable be reassigned another value?

A

No

const variables can only be assigned a value once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
94
Q

What does the error message mean?

“Identifier has already been declared”

A

It’s letting you know that the variable name has already been used by another variable; it can’t be reused or reassigned a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
95
Q

Iet is a variable that is similar to var because … ____

A

it’s dynamic enough to adjust to new
information (ie. like a game score)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
96
Q

How does let offer greater protection against duplication?

A

It prevents errors due to duplication
by informing you of an error in the console.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
97
Q

With JavaScript do you have to be careful about spacing?

A

It’s more flexible than other programming languages in that you can add spaces, tabs, line breaks without breaking the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
98
Q

Should you include a space before and after an equal sign?

True or false.

A

True

Easier to read if there is a space before and after the equal sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
99
Q

Should const daysInWeek = 7; have spaces?

A

No.

No spaces between variable names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
100
Q

What are number data types used for?

A

Calculations like adding, subtracting, multiplying, dividing

Practical: Total score, total costs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
101
Q

How common are strings?

A

Super common

Use all throughout programming in different forms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
102
Q

What are strings?

A

Letters, digits, expressions inside of single
or double ‘ or ‘’ quotation marks

103
Q

Do you need to be consistent with quotation marks?

A

Yes

Single or double, just be consistent.

104
Q

What does the error message invalid or
unexpected token refer to?

A

Possible typo stemming from lack of quotation
marks or lack of consistency with quotation marks.

105
Q

Should you use “” double quotation marks if you have a single quotation mark in a sentence?

‘You’re only going to live once.’

'’You’re only going to live once.”

A

The correct option is to use ‘’ double ‘’ quotation marks if you have a word or phrase that uses single quotation marks.

106
Q

Suppose you have an attribute that uses “” double quotation marks, should you use ‘’ marks in your string?

Example:

My Headline
’;

A

No

The reverse is true also.

Use single when you’re string internally
uses double quotation marks.

107
Q

How do you use the backslash in the event you want to differentiate between ‘ single quotation marks for the string and single quotation mark for a word or phrase?

A

‘I’/m a programmer!’

Use the backslash just after the internal ‘ quotation mark to indicate it’s part of the string, not the end of the string.

108
Q

What are the 3 errors in the multi-line attempt for a string?

Why does this happen?

A

Syntax error: unexpected token

  1. First line doesn’t have closing quotation marks
  2. Second line has 0 quotation marks.
  3. Third line needs an opening quotation mark.

Why?

The JS engine is treating each line as its own line.

109
Q

What symbol do you use after each line
to communicate that the next line is still part of the string?

A

/

backslash

110
Q

Why are backslashes correct in this case of a multi-line string?

A

The / makes it clear its part of the same string.

111
Q

Behind the scenes, how are strings treated by the JS engine?

A

Strings are treated as object.

112
Q

When is string is treated as an object, how does it improve functionality?

A

Strings get added functionalities like
properties and methods.

113
Q

What is the .length property?

A

.length property tells you how many characters are in a string.

114
Q

Does .length property include spaces in the character length?

A

Yes, spaces are counted in addition to letters and numbers.

115
Q

In this example, what’s the content of the string?

A

Open Sesame

116
Q

What portion of the JS code initiates the .length property?

A

passphrase.length

117
Q

Based on the .length property, how many
characters are in this example?

A

11

118
Q

How can the .length property be helpful for passwords?

A

Make sure password length is not too short, not too long.

Say between 10 and 20 characters total

119
Q

Can the .length property help with seeing if a form field is empty?

A

Yes, .length can check if 0 characters are present.

120
Q

What does the . added to a string do?

A

. helps strings tap into object
by tapping into properties and methods

121
Q

Are properties static or dynamic?

A

Properties are dynamic like a variable.

122
Q

How is method different from properties?

A

Methods focus on actions you can do.

Since it focuses on action, it’s not like a variable.

123
Q

Is .toUpperCase() a property or method?

A

Method

124
Q

Is .toLowerCase a method or property?

A

Method

125
Q

What does the .toUpperCase method do to a string?

A

It converts the content of the string to all uppercase letters.

126
Q

What does the method of .toLowerCase do?

A

It converts all the content of the string into lowercase letters.

127
Q

Why do methods like .toUppercase or .toLowerCase matter?

A

For case sensitivity purposes, letter case matters.

128
Q

How is lettercase relevant to programming?

A

Lettercase is later used for many purposes including searching in search bars or matching information in online store inventory.

129
Q

What significance does the () usually convey?

A

() shows you its a method

130
Q

In this example, using the .toLowerCase method, what happens to the letters once run through the JS console?

A

All letters in the string are lowercase

Including the I, H, and S

131
Q

Once the method of .toUpperCase is applied, how does the string content appear in the JS console?

A

I HAVE SPOKEN

Magically, all letters are capitalized…

132
Q

In the absence of a () method for .toUppercase or .toLowercase, what happens as seen in this example?

A

The letters in the string retain their original lettercase.

133
Q

What does it mean to capture input?

A

Any information that’s gathered from the end user

134
Q

What are 3 examples of capturing input?

A

Login

Form

Create a profile

135
Q

What’s another way to call methods?

A

Commands

136
Q

What does the prompt command let you do?

A

lets you ask a question from the user

137
Q

What happens when this JS snippet is run?

A

It creates a pop up dialog with the question and it can capture information from the user in the field.

138
Q

What happens when you combine a variable with a prompt?

A

The user information is stored in the variable name.

139
Q

When alert(name); is run, what does it do?

A

It gives back the answer stored in const name.

140
Q

What happens when you combine a prompt with console.log?

A

It prints the name into the JS console; it’s a message you send to yourself which can help with testing or debugging.

141
Q

Is it possible to combine strings?

‘Peter’ ‘Nystrom’

A

Yes strings can be combined together

‘Peter Nystrom’

142
Q

Why would combining strings be helpful for names?

A

You collect first and last name separately in a form.

Through combining strings, full name is displayed together.

143
Q

What is string concatenation?

A

String concatenation is the process of
adding 2 or more strings together.

144
Q

How does the + operator help with string concatenation?

A

The plus operator + helps join strings.

145
Q

Do strings add space?

A

No.

You have to add a space, to see a space.

146
Q

In the const message, do the + operators make it MORE or LESS difficult to read the content of the message?

A

Using + operator makes it harder to read, more difficult to read. There are clearer ways to have multi-line message.

147
Q

What happens to the content on the right of the assignment operator?

A

What’s on the left, takes on what’s assigned to it, from the right side of the syntax.

148
Q

What happens to the left of the equal sign?

A

right of equal sign goes on the left

combines strings of text together

149
Q

When adding to a message, what symbol do you use?

A

+= addition assignment

This adds to the message.

It replaces message + (long form)

+= (short hand)

150
Q

Why are multiple lines created with message?

A

It helps improve readability.

It helps you modify text more precisely.

151
Q

Why does it look like there’s unnecessary
space in the sentences?

A

It’s making room for essential space
that the string won’t naturally have.

152
Q

Why wouldn’t this expression work?

Error Message: assignment to constant variable

A

const variables don’t respond to += addition assignment

You have to switch const to let

The let variable is flexible to be modified/built upon.

153
Q

Why would you use a template literal over string from a spacing standpoint?

A

It’s easier to use spacing with template literals because it’s more natural, intuitive, normal to just writing a sentence.

Spaces included automatically

154
Q

What symbol do template literals use to start/end the process?

A

** backtick **

(on the same key as the tilde ~ key)

155
Q

How do you insert dynamic values into a template literal?

A

${curlybraces}

156
Q

When you embed a string with dynamic embedded expressions it is called __________.

A

Interpolation

157
Q

Can you put just about any JavaScript inside the curly braces?

A

Yes

Numbers and Calculations also

158
Q

Can you use numbers or calculations
with string interpolation?

A

Yes, string interpolations let you run calc functions.

You can even run math calculations with the curly braces

159
Q

With template literals, you don’t
need to worry about _____, ____ quotes,
or ____ quotes like concatenation.

A

spaces

single quotes

double quotes

160
Q

How do you create a new line with template literal?

A

Simply use the return button

Template literals make new lines easier.

161
Q

Is this example using template literals or concatenation?

A

Template literals

` back ticks at the start and end `

162
Q

What’s happening in the first line of code?

A

a variable is being established as const StringtoShout

the assignment operator = sign creates a

prompt or dialog window with a question

163
Q

What’s happening in the second line of code?

A

A method is applied to the variable StringToShout where all letters are transformed into uppercase letters.

164
Q

What’s happening in the 3rd line of code?

A

A template literal beings it all together.

Message + what to shout in uppercase letters

165
Q

What is the querySelector() purpose?

A

query selector helps access HTML elements

166
Q

When ‘main’ is used within queryselector,
what’s this method doing?

A

It’s scanning for the main tag
within HTML document.

167
Q

What is .innerHTML doing in this example?

A

.innerHTML is allowing the content to
be replaced old content with new content.

168
Q

Is .innerHTML a method or a property?

A

.innerHTML is a property

169
Q

What do we want the ‘main’ content to be?

A

the content of shoutMessage

170
Q

What do conditional statements do?

A

Conditional statements help programs follow
if this, then that logic to respond more intelligently.

171
Q

What’s an example of a conditional
statement
in the context of a game?

A

If the player loses all points, then the game is over.

If the player reaches 1000 points, then increase difficulty.

172
Q

What is the name of the triple = = = sign?

A

strict equality operator

173
Q

Why would you use a strict equal operator === in the context of an if/then conditional statement?

A

The strict equal operator is checking
to see if the user input matches
identically to the correct answer.

174
Q

If the person enters the word ‘Mercury’, then what happens?

A

The console.log produces the message that’s
correct to validate the user input as a valid answer.

175
Q

What happens if the person enters the wrong answer?

A

Nothing.

The current program doesn’t have a then statement that applies in the event that the user answer is wrong.

176
Q

How do you begin to establish
user feedback when the answer is wrong?

A

Use an else clause

The program receives instructions on what
to do
in the event the answer is wrong.

177
Q

What’s a good analogy to explain the
logic of if/else conditional statements?

A

Fork in the road, can only go down 1 path

178
Q

With the current if/else conditional statement,
what happens if someone enters mercury?

A

The answer is marked as incorrect because of case sensitivity in the strict equality operator the answer was specified as ‘Mercury” not mercury. Case alone shouldn’t make/break a quiz answer.

179
Q

How do you make sure that case doesn’t
interfere with correct answer in the quiz?

A

Use the .toUpperCase() to convert all responses into uppercase letters, so it automatically matches the case in the correct answer

180
Q

Is .toUpperCase a property or method?

A

.toUpperCase() is a method

181
Q

Do you have to change the correct answer to all uppercase letters in the quiz when using .toUpperCase() method?

A

Yes

The strict equality operator is using
that as a reference point to match answers and case.

182
Q

If you write the correct answer using a mixture of uppercase and lowercase letters, what happens? Why?

Example: MeRcUry

A

It’s all good. Answer is correct.

The .toUpperCase() method transforms it
into all uppercase letters.

183
Q

What’s the value of having conditional statements?

A

It makes programs more flexible
and more interesting to the end user when
conditional statements are applied well.

184
Q

What does the less than simple mean?

example: 3 < 5

A

3 is less than 5

The crocodile goes for the biggest value.

185
Q

Programming can be binary because it’s ultimately trying to determine if something is ____ or ____.

A

True or false

186
Q

What are comparison operators?

A

Symbols used to indicate relationship of values

>, <, =, ==, ===, etc.

187
Q

Is 100 > 100?

A

No

They’re equal.

Console says: FALSE

188
Q

Is (100 >= 100)?

A

Yes, 100 can be equal to 100.

189
Q

Is ( ‘100’ > ‘Apple’)?

A

Yes, numbers always come before letters.

190
Q

What is the Equality Operator?

A

==

two equal signs

191
Q

What does the equality operator == do?

A

It helps test if two values are true.

==

192
Q

Does the equality operator test the equality of different types?

A

Yes, it can see if different types are actually equal.

193
Q

Is ( ‘3’ == 3 )?

A

Yes, they are equal.

the string is converted into a number by the browser before comparing the values

194
Q

What symbols are used in a strict equality operator?

A

===

all three equal signs together in a strict equality operator

195
Q

Does a strict equality operator compare types also?

A

No

Strict equality operators are purely
based on values exclusively.

196
Q

What’s the outcome of ( ‘ ‘ === 0 )?

A

False

A strict equality operator finds that it is not the same.

197
Q

( ‘ ‘ == 0 )

What happens with an equality operator?

A

Equal values

Space is converted into a 0.

0 is equal to 0.

198
Q

Why would you use strict equality operators
over equality operators?

A

Strict equality operators are more precise,
less error prone.

199
Q

( ‘Python’ === ‘HTML’ )

A

False

Different letters.

200
Q

( ‘JavaScript’ === ‘JavaScript’)

A

True

JavaScript is equal to JavaScript

201
Q

Is the strict equality operator case sensitive?

A

Yes, strict equality operators are case sensitive.

javascript is not equal to JavaScript

202
Q

Not equal to is represented by the inequality operator

A

!=

inequality operator consists of !=

203
Q

What is the strict not equal operator?

A

!==

! two equal signs

204
Q

What is the logical not operator?

A

!

exclamation mark

205
Q

Why is it better to use the strict inequality operator?

A

Strict inequality operators !== prevents errors and misinterpretation of values from the browser.

206
Q

( ‘10’ !== 10)

A

True they are not equal

First is in a string

Second is a number

207
Q

( ‘java’ !== ‘Java’ )

A

True, it’s not equal

Lettercase difference

208
Q

( -59 !== -59 )

A

False

They are equal numbers.

It’s like saying -59 is not strictly equal to -59.

209
Q

What two values are booleans?

A

True or false

210
Q

Why would you use booleans?

A

When you want the simplicity of yes/no

true/false in your programming

211
Q

How would you write a flexible variable that can store an initial default value of false – with a variable named correctGuess

A

let correctGuess = false;

212
Q

In a guessing game, what variable type would you use to indicate that the correct answer is very specific, not changing?

A

let variable

213
Q

How would you create a variable that writes the question using a dialog window to the end user?

A

const guess = prompt(‘Guess a number between 1 and 10’);

214
Q

In this example why is there a + sign before guess?

A

+ symbol converts a string into a number.

215
Q

What kind of statement changes the default
false value into a true value?

A

It happens through a conditional statement

216
Q

Write a conditional statement where +guess is strictly equal to the variable number in parenthesis. Then change the correctGuess to true if the guess matches exactly the correct number. Remember to include a ; at the end of the true statement.

A

if ( +guess === number ) {
correctGuess = true;
}

217
Q

How do booleans and conditional statements help create
wrong/right answer messages?

A

You use booleans with conditional statements
to specify true or false. This way it writes
the correct message.

218
Q

What should the console.log say if the answer is wrong?

A

console.log(‘The answer is wrong.’);

219
Q

How would you insert the correct number
into the wrong answer message?

A

console.log(‘Sorry, the number was ${number}.’);

220
Q

Why is the weather an example of programming
for multiple possible outcomes?

A

If raining, stay in, read a book

If sunny, go out, swim in the pool.

If snowing, go out, ski away.

The weather impacts the activity outcome.

221
Q

What type of statement helps with programming multiple outcomes?

A

else, if statements help with programming
multiple outcomes

222
Q

Each keyword represents

A

a possible outcome.

223
Q

Does it move to the second level, else if,
if the first condition is true?

A

No

It flows in hierarchal order

224
Q

Why does the final else not have a condition?

A

It literally is the last resort in the statement, indicating the previous two conditions were both false. It’s the final answer.

225
Q

How do you create multiple outcomes within an else/if statement?

A

Use multiple else if segments to meet your needs

226
Q

What symbols represent the and operator?

A

&&

And Operator

227
Q

Why would you use an && and operator?

A

When a program needs to be true in 2
or more
conditions for an action to be relevant.

228
Q

How does the && and operator apply to the weather-based activity analogy?

A

In order to take of action of swimming

First, the weather has to be sunny

Second, you have to know how to swim.

229
Q

What’s 3 practical scenarios for the and operator &&?

A

When you need to test for a range

Say air temperature range

Flu range

Price range

230
Q

What does age represent?

A

It’s the starting value, the key
testing variable for the scenario that follows.

231
Q

Is it testing everything simulaneously with the and operator?

A

No

It checks left

It check right

Then produces outcome

232
Q

Given this example, what outcome would the console.log give?

A

True

25 is greater than 20

25 is less than 30

233
Q

What’s the shortcut to bring up a previous
condition in the JS console?

A

Press the up arrow

234
Q

Can a string value pass this range?

A

No

A string value is made up of letters in this case.

It can fit in the numerical range.

235
Q

If the age is changed to 10, what happens?

A

The statement becomes false.

236
Q

What’s a practical scenario where the
and operator && comes in handy on a website?

A

Login screen

make sure that the username & password
are filled in before processing the login credentials

237
Q

With the OR operator, do both statements need to be true?

A

No

If 1 of the 2 is true, then the
entire statement value returns as true.

238
Q

What characters represent the or operator?

A

2 pipe characters

||

239
Q

What’s the weather-activity analogy with the or operator?

A

If it’s hot outside or the pool is closed, you can go swimming in the ocean.

If it’s snowing outside and the skis are too heavy, you can go snow mobiling.

The main idea: there are multiple options, alternatives

240
Q

Imagine you have a terms of service agreement, and the user needs to indicate yes to consent to the terms. How can you use the or operator in this case to indicate approval?

A

Yes

Y

via or operator

241
Q

Which is the or operator in this example?

A

||

2 pipe characters

242
Q

Is it testing it as one entire statement?

A

No, it’s testing each half of the

statement to see if it’s true or not.

243
Q

What if you set the value of agree = ‘n’; what happens?

A

It states that the statement is false

It is neither y nor yes

Neither condition is true, so it defaults to false

244
Q

Can you use shorthand with or operator? ||

A

No

Both sides need to be complete

245
Q

Is there a limit on the number of and operators you can put into a program?

A

No

There is NO limit on and operator &&,
just each portion needs to be true
for it to be a true outcome.

246
Q

Can you have multiple or operators?

A

Yes you can have multiple or operators ||

Only takes 1 statement to be true for it to default to true

247
Q

Why do you add comments to your code?

A

To leave messages for why/how things
work in the program works

248
Q

How are comments helpful to other developers?

A

It helps explain how it works or reasoning behind code.

249
Q

What is a single line comment in JavaScript?

A

// Single-line comment

250
Q

How do you do a multi-line comment in JavaScript?

A

/* Multi-line
comment
*/

251
Q

Should the comment appear below
or after the section of code?

A

Before the code is where
the comment should appear.

252
Q

How do you use a multi-line comment when you have multiple ordered steps?

A
253
Q

Should you use a bunch of inline comments?

A

No

Makes the code harder to read