Reputation: 43
Beginners question about adding variables to a function:
Putting in the amounts :
var calcdiscount = function () {
var test = $('#discount').val();
if (test.length > 0 && $('#discount')[0].checkValidity()) {
PizzaSizeCost(2);
}
else {
PizzaSizeCost(0);
}
}
;
Getting out the amount:
var PizzaSizeCost = function (test) {
How can I do this ?
Upvotes: 0
Views: 34
Reputation: 5346
A function
uses return
to, well, return values to the caller. So:
function testValue(value) {
if (value < 100) {
return "Small";
} else {
return "Large";
}
}
var example = testValue(75);
// Now example = "Small"
var secondExample = testValue(125);
// secondExample = "Large"
Upvotes: 2