Add a product to the cart when a button is clicked

How do I get this code to work when I click a button on my product page?
I need to add a product to the cart so that the person can go to a measurement page, fill in their measurements and return to the product page to purchase the item.
Thanks Keith Green
$w(“#myButton”).onClick( () => {
.then( () => {
console.log(“Product added”);
} )
.catch( (error) => {
} );
} );