The jsfiddle.net code below produces Uncaught SyntaxError: Unexpected token ( and the text "Here", but does not produce the result I wish to study, which will help me understand callbacks in functions and how their return value, true/false in my case, can be used to determine which of two things are to be computed.
I would like help removing the syntax error so I can see the result.
function checkPos(input, callback) {
if (input > 0)
function () {
callback(true);
} else
function () {
callback(false);
}
}
function dosomething(number) {
var diff = 10 - number;
checkPos(diff, function (e) {
return e;
});
}
var count = 1;
var multiplier = 6;
var result;
if (dosomething(11)) result = 5 + count
else result = 5 - count
document.getElementById("demo").innerHTML = String(result*multiplier);
The html code is simply as follows.
<body>Here
<p id="demo"></p>
</body>
functionkeywords doing there incheckPos? I mean, what are they supposed to do there?returnvalue of a callback function is returned to where it was called, not where the function was defined. YourdoSomethingwon't work.doSomethinga callback parameter as well, which you call from the other callback. See also stackoverflow.com/q/14220321/1048572 and possibly stackoverflow.com/q/23667086/1048572. IfcheckPosis not asynchronous, remove the callback style altogether and justreturn.