0

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 ?

2
  • 1
    How can I do this ? Do what? Commented Jan 18, 2015 at 12:50
  • How Can I put in the amount and get it out again? .... Obvious.../ Commented Jan 18, 2015 at 12:54

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

1 Comment

This is basic JavaScript by the way, not JQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.