I want to append "%" sign after getting "quizpoints" value

I want to append % sign after getting "quizpoints" value.

var player = GetPlayer(),
  xhttp = new XMLHttpRequest,
  targlink = "https://cluelabs.com/stencil/display/widget-table-save-row?chart=MTA2N3wyMDY5fDUzZWU0NzFiOTdkOWRiYzg2NWFhNmNmNjhjYmFiZTcw";

targlink = targlink + "&newnum=" + encodeURIComponent(parseFloat(player.GetVar("quizpoints"))) + "&newtext=" + encodeURIComponent(player.GetVar("learnername")), 
xhttp.onreadystatechange = function() {
  4 == this.readyState && 200 == this.status && player.SetVar("stencilrendered", parseInt(player.GetVar("stencilrendered")) + 1)
}, 
xhttp.open("GET", targlink, !0), 
xhttp.send();

3 thoughts on “I want to append "%" sign after getting "quizpoints" value”

  1. Your code is a mess of attempted "cleverness".

    It is unreadable and wrong.

    You have commas where they do not belong. You need to start a new set of vars as you can see now I formatted the question. You break the list but the statements after the targlink = targlink + "&newnum=" do not even belong in a var list

    This might work better for you, it is certainly more readable

    const player = GetPlayer();
    const stencilRendered = +player.GetVar("stencilrendered");
    const xhttp = new XMLHttpRequest;
    const targlink = new URL("https://cluelabs.com/stencil/display/widget-table-save-row?chart=MTA2N3wyMDY5fDUzZWU0NzFiOTdkOWRiYzg2NWFhNmNmNjhjYmFiZTcw");
    
    targlink.searchParams.append("newnum",player.GetVar("quizpoints"))
    targlink.searchParams.append("newtext",player.GetVar("learnername"));
    
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
       player.SetVar("stencilrendered", stencilRendered + 1)
      }  
    };
    xhttp.open("GET", targlink.toString(), false);
    xhttp.send();
    
    Reply

Leave a Comment