6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript 関数の練習問題

Posted at

js.png

練習問題

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();
6
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?