具有多种条件的开关/外壳必须是真实的 [英] Switch/case with multiple conditions which have to be true
本文介绍了具有多种条件的开关/外壳必须是真实的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,
我必须编写一个包含多个条件的代码,这些条件必须是真的,我不知道我是如何工作的。
我在论坛上搜索过并试过谷歌,但它根本没有帮助我。
var one = prompt( text,< span class =code-string> )
var two = prompt( text, )
var three = prompt( text, )
var four = prompt( text, )
switch (一,二,三,四){
case (一个> = x&&一个< = y):
case (两个> = x&& two< = y):
case (三个< = x):
case (四个< = x):
document .write( yes );
break ;
默认:
alert( 没有跨度>);
break ;
我试过这样,但是当我输入4个值,我总是收到提醒..
4个案例必须是真的,否则我不能用它。
如何在javascript中完成?
解决方案
参见http://www.w3schools.com/js/js_switch.asp [ ^ ]正确使用开关
构造。您的样本在语法上甚至不正确,因此它永远不会起作用。您描述的实际问题不适用于开关
,因为它实际上是以下形式:
if (test1为TRUE
AND test2为TRUE
AND test3为TRUE
...
Hey,
I have to write a code with multiple conditions which have to be true and I have no idea how I get this working.
I searched the forums and tried google aswell but it didnt help me at all.
var one = prompt("text", "")
var two = prompt("text", "")
var three = prompt("text", "")
var four = prompt("text", "")
switch (one, two, three, four) {
case (one >= x && one <= y):
case (two >= x && two <= y):
case (three <= x):
case (four <= x):
document.write("yes");
break;
default:
alert("no");
break;
I tried like this, but when I enter the 4 values, I alway get the alert..
The 4 cases have to be true, otherwise I can't use it.
How is it done in javascript?
解决方案
See http://www.w3schools.com/js/js_switch.asp[^] for the correct use of theswitch
construct. Your sample is not even syntactically correct, so it will never work. The actual problem you describe does not lend itself to aswitch
, as it is really of the form:
if (test1 is TRUE AND test2 is TRUE AND test3 is TRUE ...
这篇关于具有多种条件的开关/外壳必须是真实的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文