diff --git a/js/index.js b/js/index.js index 3be1f60..7276f6a 100644 --- a/js/index.js +++ b/js/index.js @@ -1,10 +1,8 @@ "use strict"; -function sum(...nums) { - let total = 0; - for (let num of nums) { - total += num; - } - console.log(`合計は${total}です`); +function getTriArea(base, height) { + let area = 0; + area = base * height / 2; + return area; } -sum(1, 2, 3, 4); -sum(5, 10); +let menseki = getTriArea(4, 3); +console.log(`面積は${menseki}です`); diff --git a/src/index.ts b/src/index.ts index 65c7890..244719f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,8 @@ -function sum(...nums:number[]):void{ - let total =0; - for(let num of nums){ - total +=num; - } - console.log(`合計は${total}です`); +function getTriArea(base:number,height:number) +:number{ + let area:number=0; + area=base*height/2; + return area; } -sum(1,2,3,4); -sum(5,10); \ No newline at end of file +let menseki=getTriArea(4,3); +console.log(`面積は${menseki}です`); \ No newline at end of file