for 循环似乎运行良好,但未能更新元素变量。我的意图是:
<h6>Q1</h6>
<h6>Q2</h6>
<h6>Q3</h6>
相反,实际结果是:
<h6>Q1</h6>
<h6>Q1</h6>
<h6>Q1</h6>
function results () {
var listResults = '';
var i=0;
const element = `
<h6>Q${i+1}</h6>
`;
for(x=0; x < 3; x++) {
listResults += element;
i++;
}
return listResults;
}
console.log(results())