0
I have a problem with this code:
function calculate() {
var input = document.getElementById("input").value;
var x = input;
for (var i = input; i > 1; i--) {
x += i;
}
var j = 1;
var k = 1;
var number = 1;
var output;
while (k < x) {
output = number.toString() + " ";
number += 1;
if (number = j) {
output += "\n";
j = 1;
k++;
}
}
document.getElementById("output").innerHTML = output;
}
<input id="input" type="number" />
<button onclick="calculate()">Calculate</button><br/>
<span id="output"></span>
It always returns 1. Can anyone please help me?
Why not edit the question and describe what the code should do?
– Woss
if (number == j)
instead ofif(number = j)
you are testing and not assigning... And yet, you have an infinite loop in your algorithm, do a table test.– Leandro Angelo
Then see that the solution is much simpler https://www.rushis.com/floyds-triangle-javascript-code/
– Leandro Angelo
The value entered in
input
will define what?– Sam