In the development process , I met the demand for the output of multiple-choice questions .
So you need to output A、B、C、D、E Options such as .
We can define an array of characters to solve .
You can also use between characters ASCII The relationship between codes is easier to solve .
The solution is as follows :
let letter = 'A' for(let {value} of questionAttrCopys){ if(type==3){ $(".result").append( ` <div>${value}</div> ` ) }else{ $(".result").append( ` <div>${letter}.${value}</div> ` ) letter = letter.charCodeAt() + 1 letter = String.fromCharCode(letter) } }
From the above code ,
Change the letter to ASCII The method of code is :
letter.charCodeAt()
take ASCII The method of converting code into corresponding letter is :
String.fromCharCode(letter)