Skip to content

Instantly share code, notes, and snippets.

@nau
Created August 31, 2013 10:31
Show Gist options
  • Save nau/6397422 to your computer and use it in GitHub Desktop.
Save nau/6397422 to your computer and use it in GitHub Desktop.
JScala supports ternary operator expressions.
val ast = javascript {
def main(args: Array[String]) {
val language = if (args.length == 0) "EN" else args(0)
val res = language match {
case "EN" => "Hello!"
case "FR" => "Salut!"
case "IT" => "Ciao!"
case _ => "Sorry, I can't greet you in " + language + " yet"
}
console.log(res)
}
}
println(ast.asString)
{
function main(args) {
var language = (args.length == 0) ? "EN" : args[0];
var res;
switch (language) {
case "EN":
res = "Hello!";
break;
case "FR":
res = "Salut!";
break;
case "IT":
res = "Ciao!";
break;
default:
res = ("Sorry, I can't greet you in " + language) + " yet";
break;
};
console.log(res);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment