Var month = Number(dob.substr(4, 2)) - 1 Ĭonsole. In JavaScript, you use a do-while loop when you are not sure how many times you will execute the loop body and the loop body needs to execute at least once. So you need to first find the max from first elements of grade array. Remember the grade here is two dimentional array and you are comparing the first index element of grade with age. This is probably the best solution for you if you are looking for age and grade. The code above tries to look through your (array)grade and returns the first occurrence of the value whose first item equals the calculated age.Īlternatively, if you’re particular about the while loop, you can do the following: //age = 7 console.log(yourGrade ? yourGrade : "You’re either too young or too old") ![]() Once the expression becomes false, the loop terminates. ![]() The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. ![]() You are comparing (int)age with an (array)grade The most basic loop in JavaScript is the while loop which would be discussed in this chapter.
0 Comments
Leave a Reply. |