Write a function to take the remaining value data exchange

Write a function to add 5 to each digit, then replace the number with the remainder of dividing by 10, and then swap the first and fourth digits, and the second and third digits, pass in the original text, and output the cipher text

<body>
    <input type="text" id="txt1">
    <input type="button" id="btn">
    <input type="text" id="res">
</body>
<script>

    var txt1 = document.getElementById("txt1");
    var btn = document.getElementById("btn");
    var res = document.getElementById("res");
    
    btn.onclick = function(){
       	获取输入框数据
        var n = txt1.value - 0;
	    解析千,百,十,个,每位数字
	    每位都和10取余
        var a = parseInt(n/1000)
        var b = parseInt(n/100)%10
        var c = parseInt(n/10)%10;
        var d = n%10;

       	 处理数据
       	 每位都加5
        a = (a + 5)%10;
        b = (b + 5)%10;
        c = (c + 5)%10;
        d = (d + 5)%10;
        
         打印结果(直接改变数据位置)
         第一位和第四位交换
         第二位和第三位交换
        res.value = "" + d + c + b + a;
    }

Guess you like

Origin blog.csdn.net/qq_26705343/article/details/111384976