在Javascript中添加百分号

GMa*_*Man 3 javascript percentage

在Javascript中我试图在我的函数结束时添加%符号,但是当我测试它时我得到NaN.

function percentReadyForDegree(creditsEarned) { 
    return Math.round((creditsEarned / 71) * 100 + "%");
}  

percentReadyForDegree(30);
Run Code Online (Sandbox Code Playgroud)

elc*_*nrs 7

你需要传递一个号码Math.round.在你的代码中,你传递一个字符串.操作添加标志:

return Math.round(creditsEarned / 71 * 100) +'%';
Run Code Online (Sandbox Code Playgroud)