+ 1
JavaScript code
So I have been working with some codes and input event but sometimes I have to face the same issue everytime. My input result is cleared by default, but once I type a value it will give me the result I want and that's great, but once I erase the input field, it has a number because the function is taking an empty field as a 0. Can anybody tell me how to get rid of that? Thanks in advance. https://code.sololearn.com/WbG620PSJTlI/?ref=app
3 Answers
+ 1
Like this?
const inputCelcius = document.getElementById('inputCelcius');
inputCelcius.addEventListener('input', function CelciusToFahrenheit(celcius){
const fahrenheit = ((celcius.target.value * 1.8) + 32);
const returner = document.getElementById('returnCelcius');
if (inputCelcius.value.length == 0)
{
returner.value = null;
}
else
{
returner.value = fahrenheit;
}
})
+ 1
Steven M Just like that! Thank you very much. I just realized what you did there and now I know why I couldn't make it work. I appreciate it.
+ 1
Endert Villanueva happy to help đ đ