Your problem is that you are comparing the value of - i - with the
results of the expressions used in the - case -s. Those expressions,
such as - I < 10 -, will have Boolean results, so only true or false.
Code that will do what you appear to want would be more like:-
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var i = 10;
switch (true) {
case i < 10:
document.write("i = "+i+" is less than 10\n");
break;
case i > 10:
case i < 0:
document.write(
"i = "+i+" is either bigger than 10 or less than 0\n"
);
break;
case i === 10:
document.write("i = "+i+" is equal to 10\n");
break;
default:
document.write("This won't be printed anyway\n");
}
</script>
</body>
</html>
- where - true - is used with the - switch -, and then matches
whichever (or rather, the first) of - case - expressions evaluates to
true. However, that is a very non-obvious piece of code and I would
tend to avoid it (probably using an - if/else - structure instead in
this situation).
Richard.