top of page

Forum Posts

hypemodedesigns
May 31, 2023
In Coding with Velo
Hey, everyone. I've been creating a pizza builder using velo and I'm trying to figure out a way to refactor my code so I'm not repeating a ton of functions. I've got this function I wrote to handle showing/hiding the topping images on the pizza. There will be quite a few toppings option so repeating this 20 times or whatnot will be super inefficient. $w('#pepperoniCheckbox').onChange(() => { if ($w('#pepperoniCheckbox').checked) { $w('#pepperoni').show(); } else { $w('#pepperoni').hide(); } }); I also have this function which handles selecting the pizza size, transitioning to the toppings container and presenting a message to show what size was chosen. $w('#pizzaSizeSmall').onClick(() => { let buttonText = $w('#pizzaSizeSmall').label; let fadeOptions = { "duration": 250, "delay": 0 }; $w('#toppingsContainer').show("fade", fadeOptions); $w('#pizzaSizesContainer').hide("fade", fadeOptions); $w('#pizzaSizeMsg').text = `Your selected size is ${buttonText}!`; }); Like I said, I don't think repeating all these functions is the best way to go about this. I figure there has to be a way to refactor this to be more efficient. I'm pretty new to javascript so I'm not sure how to go about it. Anyone have any suggestions?
0
8
66

hypemodedesigns

More actions
bottom of page