I am currently using JavaScript with HTML to create a number input, and once a number is input, an option from a select list tells whether to double the number or not. I feel I have done everything correctly, however, when I run my code and select yes to double, the output number is the number input and does not double. I am assuming my if statement is incorrect but I am not sure, I am new to JavaScript. Appreciate any feedback.
HTML
<body>
<input id = 'number' name = '' value = '' class = ''>
<select id = 'double' name = ''>
<option value = 'Y'>YES</option>
<option value = 'N'>NO</option>
</select>
<button id = 'go' class = ''>GO</button>
<input id = 'result' name = '' value = '' class = ''>
<script src = 'js/javascript 03.js'></script>
</body>
JavaScript
document.getElementById('go').onclick = function () {
var number = document.getElementById('number').value;
var double = document.getElementById('double').value;
number = parseFloat(number);
if (double == 'Y') {
number * 2;
};
document.getElementById('result').value = number;
};
number * 2does indeed double the number... but with no=in that line it doesn't get assigned to anything.number, usenumber = number * 2;=and values is invalid html, i'm not quite sure that it will even render properly.if(double == 'Y')check...