Home > front end >  Why can't input the following 11 o 'clock time pop up in the morning
Why can't input the following 11 o 'clock time pop up in the morning

Time:09-27



<meta charset="utf-8" & gt;
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
<meta HTTP - equiv="X - UA - Compatible" content="ie=edge" & gt;
Document
<script>
//class assignments 1
Var time=prompt (" please enter the current time);
If (time & gt; 23 points'=') {
Alert (' good night ');
} else if (time & gt;='20') {
Alert (' good evening ');
} else if (time & gt; 18 points'=') {
Alert (' good evening ');
} else if (time & gt; 13 points'=') {
Alert (' good afternoon ');
} else if (time & gt;='11') {
Alert (' good afternoon ');
} else {
Alert (' good morning ');
}
</script>

<body>


CodePudding user response:

Is this your string comparison
"9" and "11" is to take the first character comparison of two strings
"9" in the code is greater than the "1" coding
So "nine" is greater than the "11"

You should be using numerical comparison,
Var time=parseInt (prompt (" please enter the current time), 10);
If (time & gt; 23)={
Alert (' good night ');
} else if (time & gt; 20)={
Alert (' good evening ');
} else if (time & gt; 18)={
Alert (' good evening ');
} else if (time & gt; 13)={
Alert (' good afternoon ');
} else if (time & gt; 11)={
Alert (' good afternoon ');
} else {
Alert (' good morning ');
}

CodePudding user response:

Ha ha thanks just finished hair and then find the problem
  • Related