Home > Software design >  Conditional text change for div class
Conditional text change for div class

Time:12-09

I have a list of grades on web page with identical span class. I Would need to append the current numeric grade and add a alphabet grade after the number. Current information is a text field and i would first need to parse the first 3 characters to identify the number. Then i would need to create a 5 level condition to give correct alphabet based on the number (example 0-40 = D, 40-60 = C, 60-80= B and 80-100 = A). Im newbie and just cant make it to work.

Grades list

I am able to update update the text, but when trying to parse and create conditions just was not able to make it work.

var elements = document.querySelectorAll('.score_value');
for ( var i=elements.length; i--; ) {
    elements[i].textContent  = "something else";
}

all the help would be appriciated

CodePudding user response:

try with

elements[i].innerText  = "something else";

CodePudding user response:

To parse integer in javascript, use parseInt() then include the parsed result in a condition to append what you want to text.

  • Related