I am new to JavaScript and wondered if there is a more streamlined way of writing this code:
var choices = "ABBCD" // A string containing the letters A-D
var total = 0
function calculate() { // Iterate through choices and add to total depending on the letter
for (var i=0; i<choices.length; i++) {
if (choices[i]=="A") {
total+=1;
} if (choices[i]=="B") {
total+=2;
} if (choices[i]=="C") {
total+=3;
} if (choices[i]=="D") {
total+=4;
}
}
}