JavaScript基礎 | choco

choco

Design,Photo

★for文

for(var i = 0; i < 1000; i ++){
document.write("テキスト");
}

★よく使う組み合わせ


a = Math.floor(Math.random()*100);//変数「a」に、整数0~100の乱数を代入


★よくある計算


意味 使い方 説明
Math.ceil(n) 小数点以下を繰り上げ a = Math.ceil(1.55); 変数「a」に「2」を代入
Math.floor(n) 小数点以下を繰り下げ a = Math.ceil(1.55); 変数「a」に「1」を代入
Math.round(n) 小数点以下を四捨五入 a = Math.ceil(1.55); 変数「a」に「2」を代入
Math.random() ランダム a = Math.ceil() 変数「a」に0以上、1未満の乱数を代入