I’m not competent when it comes to JavaScript and have been reading articles, which I don’t really understand, and watching YouTube videos. I can’t work out what is wrong or missing from the following code (which is modelled on a YouTube example). It works for the most part but a price update is missing. Please see the images for what I would like to do. All help would be much appreciated.
Teri
$w.onReady( function () { //calculate basic price
$w(‘#wordCount’).onChange( () => {
var words = Number($w(‘#wordCount’).value);
var basicRate = “0.015”;
var basicPrice = words*basicRate;
$w(‘#total’).text = parseFloat(basicPrice).toFixed(2).toString();
$w('#express').onChange( () => {
var returnRate = Number($w(‘#express’).value);
var returnPrice = basicPrice*returnRate;
$w(‘#total’).text = parseFloat(returnPrice).toFixed(2).toString();
PROBLEM: returnPrice doesn’t update when wordCount is increased/decreased AFTER the return is selected. Only the basicPrice updates. I need the returnPrice to update too. The total below should say 18.75 to include the return.
Hi, thank you for responding. Removing “” doesn’t make the calculation do what I need it to do - it functions in the same way as before, but thank you for teaching me something new! I didn’t know that about “”.
That doesn’t work either I’m afraid. I just think something is missing from the code. I just don’t know what it is. I watched another video and thought maybe I need a for statement… but I have no idea.
We can now debug this; normally/often, I would log to the console but to make it easier for you for now, we can have the information displayed right over the web page.
Hi, Thanks for your help Unfortunately, that doesn’t work. I think I may need a for with a loop statement for the wordCount change so that it recalculates or something. I’m not sure… I will keep researching.