Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript calculates the checksum including 10 as a solution

Janechen88

New Coder
Hello dear community,

I have a problem and I don't know exactly how to solve it.
I have a code that calculates the checksum of a number and then outputs it.

I would now have to adapt the code so that the number "10" can also come out as a solution.
That means the checksum of 91 should be 10 and not 1 (so the number must be >10 so that it calculates the checksum)

how can I add an if condition or something else to my code that I achieve this result.

I would be really grateful for suggestions and solutions 🙂



JavaScript:
jQuery( function( $ ) {
 
 
  $("input[name='wpcf-geburtdatumzahl1']").change(quersumme);


  function quersumme() {
       
   
        var tmp = $("input[name='wpcf-geburtdatumzahl1']").val().split('');
        var quer = 0;
   
        for (var i=0; i < tmp.length; i++) {
          quer += Number(tmp[i]);
        }
       
   
        var round2 = quer.toString().split('');
        var round2_res = 0;
        for (var i=0; i < round2.length; i++) {
          round2_res += Number(round2[i]);
        }


        $("input[name='wpcf-loesungszahl01']").val(round2_res);
   
         
}
   
} );
 
Last edited by a moderator:

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom