0

これを変更して実際に数値を追加する方法を誰かが説明できますか? 私はコーディングが初めてで、メモ帳も使用しているので、構文でエラーが発生することはありません。

私のJavaScript:

function street() {
    var x=Math.floor(Math.random()*2 + 1);
    var z=document.getElementById("test")
    if (x == 1) {
        alert('This should add 1');
        z.innerhtml = z + 1
    }
    else if (x == 2) {
        alert('This should add 2');
        z.innerhtml = z + 1;
    }
}

そして私のHTML:

<p>Adding</p>`
<p id="test">0</p>
<button type = "button" onclick "street()">Add</p>
4

4 に答える 4