0
Hello, it’s my first post on this site and I would like a help, I need to create a calculator that the user can put the name so that when Alert displayed the result, the name appeared, for example: ''Hello, Marcos, the result of the sum is: X''
the code is below, I just need the modification to create the box to write the name and the modification in Alert.
from now on thanks.
<html>
<header>
<title>Calculadora</title>
<script type="text/javascript">
function somarValores(){
var n1 = document.getElementById("s1").value;
var n2 = document.getElementById("s2").value;
var n3 = parseInt(n1) + parseInt(n2);
alert(n3);
}
function multiplicarValores(){
var n1 = document.getElementById("s1").value;
var n2 = document.getElementById("s2").value;
var n3 = parseInt(n1) * parseInt(n2);
alert(n3);
}
function dividirValores(){
var n1 = document.getElementById("s1").value;
var n2 = document.getElementById("s2").value;
var n3 = parseInt(n1) / parseInt(n2);
alert(n3);
}
function subtrairValores(){
var n1 = document.getElementById("s1").value;
var n2 = document.getElementById("s2").value;
var n3 = parseInt(n1) - parseInt(n2);
alert(n3);
}
</script>
</header>
<body>
Hello world
<legend>somas</legend>
<label>Valor 1:</label>
<input id="s1" type="text"/>
<label>Valor 2:</label>
<input id="s2" type="text"/>
<button id="somar" onclick="somarValores()">Somar</button>
<button id="multiplicar" onclick="multiplicarValores()">multiplicar</button>
<button id="dividir" onclick="dividirValores()">dividir</button>
<button id="subtrair" onclick="subtrairValores()">subtrair</button>
</body>
</body>
</html>
Thank you very much!
– Paulo Meurer