I have this function:
function RemoveProduct() {
if (confirm("Poista?") == return true) {
return true;
} else {
return false;
}
}
When you click a “remove” button on the page, it should ask if it should remove a product, and if the answer is yes, it will remove it.
But as far as I know, I can’t use another brackets on the if sentence conditions?
How this should be done?
When you compare a return value to
trueyou shouldn’t usereturn true, justtrue:You don’t even need to do the comparison, as the result from
confirmis a boolean value:And you don’t even need the
ifstatement, you can just return the result fromconfirm:Remember to use
returnwhen you use the function in an event. Example: