1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
What is the keyword that converts "1.5" to 1? | parseInt | parseInt | |
Number is a keyword that converts "1.5" to 1.5. What is another keyword that does the same thing? | parseFloat | parseFloat | |
Convert the string in the variable price to a decimal number if the string is a decimal or an integer if the string is an integer. Assign the result to the same variable. | price = parseFloat(price); | price=parseFloat\(price\); | |
A string has been assigned to the variable x and another string assigned to the variable y. The strings may or may not be integers. In a single statement add x converted to an integer plus y converted to an integer. (Convert and add all in the same statement). Assign the result to tot, which hasn't been declared beforehand. | let tot = parseInt(x) + parseInt(y); | lettot=parseInt\(x\)\+parseInt\(y\); | |
Convert a string represented by a variable to an integer if the string is an integer, or to a decimal number is the string is a decimal number. Assign the result to a second variable that hasn't been declared beforehand. Make up the variable names. | let myNum = Number(myString); | let[a-z_$][a-zA-Z0-9_$]*=Number\([a-z_$][a-zA-Z0-9_$]*\); | |
Convert a string represented by a variable to a decimal number regardless of whether the string is a decimal or an integer. Assign the result to a second variable that hasn't been declared beforehand. Make up the variable names. | let myNum = parseFloat(myString); | let[a-z_$][a-zA-Z0-9_$]*=parseFloat\([a-z_$][a-zA-Z0-9_$]*\); | |
The string variable, already declared, is num. Convert it to an integer if the string contains an integer, or to a decimal if the string contains a decimal. Assign the result to the same variable. | num = Number(num); | num=Number\(num\); | |
In a single statement, code an alert that displays the sum of 2 different strings represented by variables, converted to decimal numbers. The strings may or may not be integers. Make up the variable names. | alert(parseFloat(str1) + parseFloat(str2)); | alert\(parseFloat\([a-z_$][a-zA-Z0-9_$]*\)\+parseFloat\([a-z_$][a-zA-Z0-9_$]*\)\); | |
|
|||
|