Testing JavaScript Flashcards

1
Q

What do you think is wrong with this code as it currently is written?

A

Currently, this function is going to divide everything by 0 - which, if you remember you elementary school math, is not allowed. It’s undefined. Click to continue to see what happens in JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Can you see something wrong with the function as currently written?
function doMath() {
var x = 2
var y = 10
var answer = x * y / z;
var z = 4;
document.getElementById("output").innerHTML = "The result is " + answer;
}
A

The answer variable is being declared before the variable z has been defined, which isn’t possible. What do you think will happen? Click to continue and find out.

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

note

A
  • let’s us set variables whenever but we have to make sure that case sensitivity is the same
  • if one is upper case and other is lower case, then function won’t work
How well did you know this?
1
Not at all
2
3
4
5
Perfectly