I have a single input where I can submit text as such: name, score
I'm parsing the results so that the name is stored in a variable as a string and the score is stored in a variable as an integer. This looks quite clunky. Is there a way to parse the text without requiring five separate variables?
// capture submitted string result
var namescore = document.getElementById('namescore').value;
// split it at the comma
var parts = namescore.split(", ");
// make sure first part is a string
var pname = parts [0].toString();
// convert score string to integer
var scoreString = parts [1];
var score = parseInt(scoreString, 10);