gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Untitled conversation
- User
- Assistant
Yes, you can use HTML to create a calculator. Here is an example:
<!DOCTYPE html> <html> <head> <title>Calculator</title> </head> <body> <h1>Calculator</h1> <form> <input type="text" id="result" disabled> <br><br> <input type="button" value="1" onclick="display('1')"> <input type="button" value="2" onclick="display('2')"> <input type="button" value="3" onclick="display('3')"> <input type="button" value="+" onclick="display('+')"> <br> <input type="button" value="4" onclick="display('4')"> <input type="button" value="5" onclick="display('5')"> <input type="button" value="6" onclick="display('6')"> <input type="button" value="-" onclick="display('-')"> <br> <input type="button" value="7" onclick="display('7')"> <input type="button" value="8" onclick="display('8')"> <input type="button" value="9" onclick="display('9')"> <input type="button" value="*" onclick="display('*')"> <br> <input type="button" value="0" onclick="display('0')"> <input type="button" value="." onclick="display('.')"> <input type="button" value="=" onclick="calculate()"> <input type="button" value="/" onclick="display('/')"> <br><br> <input type="button" value="Reset" onclick="clearResult()"> </form> <script> function display(value) { document.getElementById("result").value += value; } function calculate() { var result = eval(document.getElementById("result").value); document.getElementById("result").value = result; } function clearResult() { document.getElementById("result").value = ""; } </script> </body> </html>This HTML code creates a simple calculator using a form and JavaScript functions. The
display()function is triggered when a button is clicked and appends the button's value to the input field. Thecalculate()function uses theeval()function to evaluate the mathematical expression in the input field and displays the result. TheclearResult()function resets the input field to empty when the "Reset" button is clicked.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.