Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
To calculate the sum of even or odd places of an 8digit student ID in JavaScript we can use the foll...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started