練習問題
1.アラート”OK”を表示する関数を作ろう
2.一つの文字を関数に渡し、その文字をアラートで表示
3.2つの数字を関数に渡し、たし算した結果をalertで表示
4.3つの数字を関数に渡し、たし算した結果をalertで表示
5.関数に"id名"と"色名"を渡し"p"要素の背景を変える
6-1.現在--年--月--日をリターンして結果をアラートする
1
function ok_alert(){
alert("ok");
}
ok_alert();
2
function sum(n1){
alert(n1);
}
sum("一文字");
3
function two(one,two){
var sumTwo = one + two;
alert(sumTwo);
}
two(1,2);
4
function three(one, two, three){
var sumThree = one + two + three;
alert(sumThree);
}
addTh(1,2,3);
5
function idColor(id,color){
document.querySelector(id).style.backgroundColor = color;
}
idColor("div", "red");
6
function nowTime(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var date = now.getDate();
var time = "現在"+year+"年"+month+"月"+date+"日";
alert(time);
}
nowTime();