Question: Write a JavaScript function that accepts an 8-digit student ID as a string then returns the sum based on the following criteria: If the
Write a JavaScript function that accepts an 8-digit student ID as a string then returns the sum based on the following criteria: If the last digit of the student ID is an ODD number, then sum up all the ODD places of digits of the student ID and return the result. If the last digit of the student ID is an EVEN number (include 0), then sum up all the EVEN places of digits and return the result. For example, Case 1 - Student ID = 12345679 The last digit '9' is an old number, the function would sum up all the odd places of the ID, the result will be 1+3+5+7= 16, the returned result should be 16. Case 2 - Student ID = 12345678 The last digit '8' is an even number, the function would sum up all the even places of the ID, the result will be 2+4+6+8 = 20, the returned result should be 20. You may use a switch statement associated with a for-loop or while-loop to complete the function. function calSum (studentId) { // write your code here [4 marks] Activate Windows Go to Settings to activate Windows.
Step by Step Solution
There are 3 Steps involved in it
To calculate the sum of even or odd places of an 8digit student ID in JavaScript we can use the foll... View full answer
Get step-by-step solutions from verified subject matter experts
