Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects
Exercise: Type Conversion
Number() turns the whole text into a number, parseFloat() keeps the decimal part and parseInt() returns an integer. typeof returns the name of the type, e.g. 'number' or 'string'.
Task
Form data is always text: const inputWeight = '6200', const inputLength = '9.5' and const inputTeeth = '800'. Convert them to numbers: numWeight with Number(), numLength with parseFloat() and numTeeth with parseInt(). Then store numWeight back as text in weightText with String(). Display all four values in the console together with their type (typeof).