StringObject. Substr (start, length)
1 kind of use the substr () directly extract
<script>
Var card=(prompt (" please enter the id number));
YearB=card. Substr (6, 4);
The console. The log (yearB);
YearB=2021 - yearB;
The switch (yearB> 18)={
Case true:
Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, adult, boot success!!!!! ");
break;
Case false:
Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, is a minor, suggest to find id card!!!!! ");
break;
}
</script>
The second use division
<meta charset="utf-8" & gt;
<meta HTTP - equiv="X - UA - Compatible" content="IE=edge" & gt;
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
<script>
Var card=(prompt (" please enter the id number));
Var year=card/* * 8 (10);
Var yearA=year % (10 * * 4);
YearB=parseInt (2021 - yearA);
The console. The log (card);
The console. The log (year);
The console. The log (yearA);
The console. The log (yearB);
The switch (yearB> 18)={
Case true:
Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, adult, boot success!!!!! ");
break;
Case false:
Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, is a minor, suggest to find id card!!!!! ");
break;
}
</script>