
電卓結果
BingAIに入れたプロンプト
Create a calculation that we can put into a web page. The UI will resemble a typical calculator were line numbers and operators are in grid. Put everything into a single html file.
出てきたHTMLのうち、貼り付けした部分
<div>
<input type="text" id="result"/>
<br/>
<input type="button" value="1" onclick="addToInput('1')"/>
<input type="button" value="2" onclick="addToInput('2')"/>
<input type="button" value="3" onclick="addToInput('3')"/>
<input type="button" value="+" onclick="addToInput('+')"/>
<br/>
<input type="button" value="4" onclick="addToInput('4')"/>
<input type="button" value="5" onclick="addToInput('5')"/>
<input type="button" value="6" onclick="addToInput('6')"/>
<input type="button" value="-" onclick="addToInput('-')"/>
<br/>
<input type="button" value="7" onclick="addToInput('7')"/>
<input type="button" value="8" onclick="addToInput('8')"/>
<input type="button" value="9" onclick="addToInput('9')"/>
<input type="button" value="*" onclick="addToInput('*')"/>
<br/>
<input type="button" value="." onclick="addToInput('.')"/>
<input type="button" value="0" onclick="addToInput('0')"/>
<input type="button" value="=" onclick="calculate()"/>
<input type="button" value="/" onclick="addToInput('/')"/>
<br/>
<input type="button" value="C" onclick="clearInput()"/>
</div>
<script>
function addToInput(val) {
var result = document.getElementById('result');
result.value += val;
}
function clearInput() {
var result = document.getElementById('result');
result.value = "";
}
function calculate() {
var result = document.getElementById('result');
var calculation = result.value;
var answer = eval(calculation);
result.value = answer;
}
</script>