Basics Flashcards

1
Q

What are variables?

A

Variables are “data buckets” to store a value for later

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

What are the 2 part of a variable?

A

Let age = 25

Declaration: Let age
Assignment: age = 25

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

What are the function of a declaration and assignment?

A

A declaration create a “bucket” to store some data

An assignment is the step of putting something into the “bucket”

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

What can you store in variables?

A

Strings
Numbers
Booleans

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

What are Booleans data types?

A

Data with True and False values

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

What are strings?

A

Strings are used to store text and are surrounded by quotes e.g “10283”

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

Differences between numbers integer and floated value?

A
Int = 29
Float = 5.14876

can also be signed

Int = +29
Float = -10.375
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

JS can also do arithmetic, what sign are used?

A
\+ addition
- subtraction
* multiplication 
/ Division
% Modulus
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is 10 % 6?

A

Modulus gives us the remaining so it is 4

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

let imputinterval = document.querySelector(“dancedancerevolution”).value

How can this code be read?

A

This line looks at the document and select the value present in the HTML document with id of dancedancerevolution and store it in the value imputinterval

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

How can this code be read?

h1holder.addeventlistener(“click”, sum)

A

We add an “eventlistener” into the “h1holder” where if you click on the h1holder it will run the function “sum”

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

What are the logical operators in JS?

A
== equal to (value )(x = = 8)
=== equal to (value and type) (x = = = "3")
!= not equal (value)(x != 8)
!== not equal (value and type) (x!== "3")
> greater than
< less than
>= greater or equal
<= less or equal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you write a conditional syntax?

A
if(condition is true) {
  //Do this
}else if(condition is true){
  //Do this
}else{
  //default stuff
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you write multiple conditions?

A

if (name===”leon” && status === “ballin”) {

}

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

Can you write multiple condition with or?

A

Yes you use this symbol “||”
E.g

if (day === “monday” || day === “sunday”){

}

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

How do you add a button to perform an action upon clicking?

A

document.querySelector(#id).addevEntListener(“click”, stopSnacking)

17
Q

How to get an input from a document?

A

let numOfSnakcs = document.querySelector(“input”).value

18
Q

How to make sure an input is a number?

A

wrap the code into “number” eg.

Number(document.querySelector(“input”).value)

19
Q

Create a function that takes in a word and a number. Console log the word x times where x was the number passed in

A
function wordXTimes(word, num){
  for(let i = 1; i <= num; i++){
     console.log(word)
    }
}

wordXTimes(“wonderful”, “21”)

20
Q

What are the 8 data type in JS?

A

There are 8 basic data types in JavaScript.

  • number: integer or floating-point.
  • bigint: is for integer numbers of arbitrary length.
  • string: A string may have zero or more characters
  • boolean: true/false.
  • null: for unknown values – a standalone type that has a single value null.
  • undefined: for unassigned values – a standalone type that has a single value undefined.
  • object: for more complex data structures.
  • symbol: for unique identifiers.
21
Q

What is alert for?

A

It is a built in function in JS that shows a message in the browser and waits for the user to press ok

22
Q

What are some built in function in JS to allow to interact with the user?

A
  • alert
  • prompt
  • confirm
23
Q

How do you concatenate strings?

A

With the + operator

“My” + “name”

24
Q

How can i = i + 1 be also written?

A

i++

25
Q

How can you do both a mathematical operation and assignment in one step.

A

You can use the “+=” or “-=” operator

This add operator add a value to the variable and reassign the new value to the variable

26
Q

Difference between Assignment and Comparisons

A

Assignment is done with = (one equal sign)

Comparison is done with ==/=== (2 or 3 equal signs)

27
Q

How do you alert a certain character in a string?

A

Strings can be seen as arrays and a similar syntax can be used. For example in the following string:

let str = ‘hello twitch!’

to alert the 3rd character we can code it in these different ways:

1) alert( srt [2] )
2) alert ( str.charAt(2) )

28
Q

How to make sure a string is all upper case?

A

.toUpperCase

29
Q

What is the “Math.” method?

A

Is a built-in object that has properties and methods for mathematical constants and functions.

30
Q

How can you put a variable into a string?

A

It can be done by using “${…}”

31
Q

What does the method ‘Math.random’ do?

A

It returns a number between 0 and 1

32
Q

What are API?

A
  • API are a simple interface to do something complex

- Let one thing communicate with another thing without having to know how things are implemented

33
Q

Why API can be seen as a restaurant menu?

A

Because it is a simple interface that let us interact with the kitchen even though we don’t know how to make the dishes in the menu

34
Q

What does API stand for?

A

Application Programming Interface

35
Q

What are back ticks quote `` for?

A

They are extended functionality quotes that allows to insert variables into strings using ${…}