What is the keyword for converting "1.5" to 1?
Sorry, that's incorrect. The correct answer:
parseInt
What is the keyword for converting "1.5" to 1.5?
Sorry, that's incorrect. The correct answer:
parseFloat
If JavaScript encounters a number inside quotation marks in an arithmetic expression, it temporarily converts it to a number and does the math, unless the expression includes.... Type the character.
Sorry, that's incorrect. The correct answer:
+
If JavaScript sees a plus sign, it converts any numbers to strings and concatenates.
What is the value of num?
var num = parseInt("5.6");
Sorry, that's incorrect. The correct answer:
5
parseInt doesn't round. It just lops off the decimal value.
Drag-and-drop. Holding down the left mouse button, drag the pieces to form a statement that converts the string represented by numAsString and assigns the integer to num.
Click in the box and type the next character. I'll autocomplete. Don't type spaces.
Convert the string represented by price to a number with a decimal value and assign the result to the same variable.
The correct code is:
price = parseFloat(price);
Fail-safe coding. If you type the wrong character, I'll cancel the keystroke. Type spaces.
The string "2" has been assigned to the variable x. In a single statement add x plus x converted to integers. (Make the conversion in the same statement). Assign the result to tot, which hasn't been declared beforehand.
The correct code is:
var tot = parseInt(x) + parseInt(x);
Convert a string represented by a variable to an integer and assign it to a second variable that hasn't been declared beforehand.
Sorry, that's incorrect. An example:
var myNum = parseInt(myString);
Convert a string represented by a variable to a number with a decimal value and assign it to a second variable that hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var myNum = parseFloat(myString);
The string "1.99" has been assigned to price. In a single statement convert it to 1 and assign the result to the same variable.
Sorry, that's incorrect. The correct code:
price = parseInt(price);
In a single statement code an alert that displays the sum, including decimals, of 2 different strings represented by variables, converted to numbers.
Sorry, that's incorrect. An example:
alert(parseFloat(str1) + parseFloat(str2));
Code the first line of an if statement that tests whether a string represented by a variable, converted to an integer, is greater than 1.
Sorry, that's incorrect. An example:
if (parseInt(myString) > 1) {
Time goal: 35 seconds. Convert a string represented by a variable to an integer and assign it to a second variable that hasn't been declared beforehand.
Sorry, that's incorrect. An example:
var myNum = parseInt(myString);
Time goal: 35 seconds. Convert a string represented by a variable to a number with a decimal value and assign it to a second variable that hasn't been declared beforehand.
Sorry, that's incorrect. The correct code:
var myNum = parseFloat(myString);
Time goal: 30 seconds. The string "1.99" has been assigned to price. In a single statement convert it to 1 and assign the result to the same variable.
Sorry, that's incorrect. The correct code:
price = parseInt(price);
Time goal: 50 seconds. In a single statement code an alert that displays the sum, including decimals, of 2 different strings represented by variables, converted to numbers.
Sorry, that's incorrect. An example:
alert(parseFloat(str1) + parseFloat(str2));
Time goal: 40 seconds. Code the first line of an if statement that tests whether a string represented by a variable, converted to an integer, is greater than 1.
Sorry, that's incorrect. An example:
if (parseInt(myString) > 1) {
Time goal: 50 seconds. Code the first line of a for statement. The string "0" (that's a zero in quotes) has been assigned to the variable numString. Your statement assigns to the counter, i, the string represented by numString, converted to an integer. Run it 10 times, using <, with the usual incrementing.
Sorry, that's incorrect. The correct code:
for (var i = parseInt(numString); i < 10; i++) {
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