Javascript, conditionals, higher-order functions
Hi. I'm playing around with Javascript until my book arrives. I was in the process of writing this small program as part of an on-line practice exercise:
Code:
function sum(a, b) { return a + b } |
I dont see semi-colons...according to what I recall, statements should end with a semi-colon...
Quote:
Quote:
Quote:
Luck Thor |
Javascript uses C-style syntax so statements cannot return values. You can use the ternary operator (which works the way you want if to work) though:
Code:
var opfunc = Code:
var funcs = {"+": sum, "-": difference, "*": product, "/": quotient} |
All times are GMT -5. The time now is 07:58 PM. |