Hello guys,
I’m trying to link the input from my HTML text field to my Javascript function argument.
This is my code so far:
javascript code:
function checkNum(num) {
let ascend = num.toString().split('').sort(function(a, b){return a-b}).join('');
let descend = num.toString().split('').sort(function(a, b){return b-a}).join('');
let result = descend - ascend;
return result;
}
function Kaprekar(num) {
var count = 0;
let reverseNum = num.toString().split('').reverse().join('');
let n = num.toString();
while (num !== 6174 && num !==0 && num >= 1000 && num < 10000 && n !== reverseNum) {
num = checkNum(num);
count += 1;
}
document.getElementById("txtresult").value = count;
}
let Kaprekar(num) = parseInt(document.getElementById("Text1").value);
my HTML code:
<div id = "main">
<input type="text" id="Text1" value="" name="TextBox1">
<p>Click the button to count</p>
<button onclick="Kaprekar(num)">Check</button>
<div id >
<input type="text" id="txtresult" name="TextBox3">
</div>
</div>
I want to call Kaprekar (num) from the html input text field. i have tried " let Kaprekar(num) = parseInt(document.getElementById(“Text1”).value);
". but its not working