In your code, you are every time creating a new element and appending each time.
var resultShow = document.createElement('p');
What you need to do is create a blank 'p' element with an identifier and re-use it. Eg. id="result">
Then on every enter instead of creating a new element, just use javascript selector method to replace the new value. Eg. document.querySelector("#result").innerHTML = "new calculated value";
Hope this helps.
manpreet
Best Answer
2 years ago
Ok, let me be more specific; I am making a simple Celsius to Fahrenheit, and Fahrenheit to Celsius converter aid in my learning of JavaScript.
So, I have successfully made the converter work, and have it displayed in the DOM using new 'p' elements (which I will be later adding a border around in CSS).
But what I am struggling with is having the new converted number cover the old one.
Right now, you enter a number, it gives you the conversion(inside a 'p' element), then when you convert the next number, it gives you another. Until their is a list of conversions.
What would I write into my code so that when you press "enter" the old result is replaced with the new?
Here is the code thus far (I know it is probably very basic but I am very new to JavaScript):