The keyword that rounds a number to a specified number of decimal places and converts it to a string is _____.
Sorry, that's incorrect. The correct answer:
toFixed
A number modified by toFixed winds up as a ______. Answer with 1 word.
Sorry, that's incorrect. The correct answer:
string
To force toFixed to round up in the case of an ambiguity, change the last decimal value to a ___. Answer with a number.
Sorry, that's incorrect. The correct answer:
6
The statement will round the number to an integer. Fill in the blank.
var newNum = oldNum.toFixed___;
Sorry, that's incorrect. The correct answer:
()
Drag-and-drop. Holding down the left mouse button, drag the pieces to form a statement that rounds the number represented by rawNum to 2 decimal places and assigns it to num.
Click in the box and type the next character. I'll autocomplete. Don't type spaces.
Code a statement that rounds a number represented by num to 4 places, converts it to a string, and assigns it to newNum, which hasn't been declared beforehand.
The correct code is:
var newNum = num.toFixed(4);
Fail-safe coding. If you type the wrong character, I'll cancel the keystroke. Type spaces.
Code a statement that rounds a number represented by num to no places, converts it to a string, and assigns it to newNum, which hasn't been declared beforehand.
The correct code is:
var newNum = num.toFixed();
Code a statement that rounds a number represented by n to 3 places, converts it to a string, and assigns it to dec3, which hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var dec3 = n.toFixed(3);
Code a statement that rounds a number represented by n to no places, converts it to a string, and assigns it to intgr, which hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var intgr = n.toFixed();
Code a statement that rounds a number represented by a variable to your choice of places, converts it to a string, and assigns it to another variable, which hasn't been declared beforehand.
Sorry, that's incorrect. An example:
var nStr = n.toFixed(2);
Code a statement that rounds a number represented by a variable to no places, converts it to a string, and assigns it to the same variable.
Sorry, that's incorrect. An example:
num = num.toFixed();
In a single statement round a number represented by a variable to 2 places, convert it to a string, convert it back to a number, and assign it to the same variable.
Sorry, that's incorrect. The correct answer:
n = Number(n.toFixed(2));
Time goal: 25 seconds. Code a statement that rounds a number represented by n to 3 places, converts it to a string, and assigns it to dec3, which hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var dec3 = n.toFixed(3);
Time goal: 25 seconds. Code a statement that rounds a number represented by n to no places, converts it to a string, and assigns it to myInteger, which hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var myInteger = n.toFixed();
Time goal: 30 seconds. Code a statement that rounds a number represented by a variable to your choice of places, converts it to a string, and assigns it to another variable, which hasn't been declared beforehand.
Sorry, that's incorrect. An example:
var nStr = n.toFixed(2);
Time goal: 30 seconds. Code a statement that rounds a number represented by a variable to no places, converts it to a string, and assigns it to the same variable.
Sorry, that's incorrect. An example:
num = num.toFixed();
Time goal: 40 seconds. In a single statement round a number represented by a variable to 2 places, convert it to a string, convert it back to a number, and assign it to the same variable.
Sorry, that's incorrect. The correct answer:
n = Number(n.toFixed(2));
Time goal: 45 seconds. Code the first line of an if statement that tests whether the number represented by num, rounded to 2 digits and converted to a string, has more than 4 characters in it.
Sorry, that's incorrect. The correct answer:
if (num.toFixed(2).length > 4) {
Live coding exercise:
Live coding exercise:
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to jsFiddle. See my brief demo of jsFiddle.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19