Here is the simple solution with JavaScript and using for loop to resolve this challenge :).
for
function validISBN10(isbn) { let index = 0; let checkSum = 0; let xCount = 0; for (; index < isbn.length; index++) { if (isbn[index] === 'X') { xCount += 1; } checkSum += parseInt(isbn[index]) * (index+1); } if (isbn.length !== 10) { return false; } if (isbn[isbn.length-1] === 'X' && xCount === 1) { return true; } return checkSum % 11 === 0; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is the simple solution with JavaScript and using
for
loop to resolve this challenge :).