From the course: JavaScript: Best Practices for Data

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Type cast

Solution: Type cast - JavaScript Tutorial

From the course: JavaScript: Best Practices for Data

Start my 1-month free trial

Solution: Type cast

(upbeat music) - I'm going to start out with the typecasts that I need to do, based on those comments. So first off, line 11 says I need to typecast on line 12. And line 12 is working with data.tempC which is string, but I need to typecast that to a number. And so to do that, I want to use the number wrapper and just passing tempC to that wrapper. Then down line 16, I need to cast tempF to a string. And that tempF value here I just got, that is going to be a number and so I need to make sure that that number is a string for actually logging as part of the string. So I'm going to use the string wrapper and pass it tempF. Now you may notice, on line 13, we are grabbing the third value from the data object which has a value of false. And it's a string we want to work with that as a Boolean. So you may have found if you made changes to line 13, that the app stopped working. And that's because if you're tryin' to typecast the…

Contents