I have a function that I've been working on.
Initially, I change all classes to "badge badge-secondary". Then, I check the text in the span. If it says "right" and is clicked, I update it to "badge badge-primary". If the text is "wrong" and clicked, then I change it to "class", "badge badge-danger".
I'm wondering if there's a way to make my code more concise and efficient?
function updateOrderType(ansType) {
lastAnsType = ansType;
var ansBadge = d3.select("#anstype").selectAll("span.badge");
ansBadge.attr("class", "badge badge-secondary");
ansBadge.filter(function() {
if (d3.select(this).text() == ansType) {
return d3.select(this).text() == "right";
}
}).attr("class", "badge badge-primary");
ansBadge.filter(function() {
if (d3.select(this).text() == ansType) {
return d3.select(this).text() == "wrong";
}
}).attr("class", "badge badge-danger");
}