Math Expressions: unfamiliar operators Flashcards

1
Q

Code a short form of x = x + 1; Use either of the two legal expressions.

A

x++; or ++x;

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

If x has a value of 100, what is the fastest way to reduce it to 99 with a math expression? Use either of the two legal expressions.

A

x–; or –x;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
var x = 50;
var y = x++;
What is the value of y?
A

50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
var x = 50;
var y = --x;
A

49

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

In a single statement, increment the variable num and assign its new value to a second variable, newNum, which hasn’t been declared beforehand.

A

var newNum = ++num;

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

In a single statement, decrement num and assign its original value to newNum, which hasn’t been declared beforehand.

A

var newNum = num–;

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

Using minimal code, decrement x. Use either of the two legal expressions.

A

x–; or –x;

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

What is the long version of x++?

A

x = x + 1;

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

In a single statement subtract 1 from a variable and assign the new value to another variable, which hasn’t been declared beforehand. Both variables wind up with the same value.

A

var newNum = –num;

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

In a single statement add 1 to a variable and assign its original value to another variable, which hasn’t been declared beforehand.

A

var newNum = num++;

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

Increment a variable. Use either of the two legal expressions. In a second statement, display its new value in an alert.

A

num++; or ++num;

alert(num);

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