JSFiddle - React, Tailwind, and code Playground
by Lena R
HTML
<input type = "text" class = 'firstN'> *
<input type = "text" class = 'secondN'>
<input type = "button" class = "btn" value = "=">
<br/>
<div class="result"></div>
CSS
.result {
margin-top: 30px;
height: 50px;
width: 100px;
background: yellow;
color: red;
font: 24px Verdana;
}
JavaScript
function calculate (a, b){
mult = a * b;
return mult;
}
var arg1 = document.querySelector('.firstN').value;
var arg2 = document.querySelector('.secondN').value;
var resmult = function (){// здесь уже переменная с анонимной функцией
var res = document.querySelector('.btn');
res.addEventListener('click', calculate, false);//здесь обращаемся к верхней функции
var resblock = document.querySelector('.result');
resblock.value = mult;
};
calculate(arg1, arg2);