-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
93 lines (58 loc) · 2.09 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict'
const number1 = document.getElementById("number1")
const number2 = document.getElementById("number2")
number1.addEventListener('change', radiocheck)
number2.addEventListener('change', radiocheck)
function result(op, total) {
document.getElementById("enzansi").innerHTML = op
if(!isNaN(total)){
document.getElementById("outPut").innerHTML = `計算結果は${total}です`
}else{
document.getElementById("outPut").innerHTML = "数値を入力してください"
}
}
function addResult(total){
let btn = document.getElementById("btn")
btn.addEventListener('click', aaa)
function aaa(){
const container = document.querySelector(".container")
const child1 = document.createElement("p")
container.appendChild(child1)
child1.appendChild(document.createTextNode(total))
console.log(total);
}
}
function radiocheck(){
let elements = document.getElementsByName("calc")
let checkValue = ''
for(let i = 0; i < elements.length; i++){
if(elements[i].checked){
checkValue = elements[i].value
}
}
if(checkValue == "tasu"){
let total = parseInt(number1.value) + parseInt(number2.value)
if(!isNaN(total)){
result('+', total)
addResult(total)
}else{}
}else if(checkValue == "hiku"){
let total = parseInt(number1.value) - parseInt(number2.value)
if(!isNaN(total)){
result('-', total)
addResult(total)
}else{}
}else if(checkValue == "kake"){
let total = parseInt(number1.value) * parseInt(number2.value)
if(!isNaN(total)){
result('✕', total)
addResult(total)
}else{}
}else if(checkValue == "wari"){
let total = parseInt(number1.value) / parseInt(number2.value)
if(!isNaN(total)){
result('÷', total)
addResult(total)
}else{}
}
}