My JavaScript is adding inputs as strings. How can I turn them into integers to give me a correct total amount?

My JavaScript is adding inputs as strings. How can I turn them into integers to give me a correct total amount?
0

#1
<!DOCTYPE html>
<html>
<head>
	<title>This is a test</title>
	
</head>
<body>
<form id="form1">
	Size: <input type="number" name="sizes" size="10"><br>
	Bow: Yes<input type="radio" name="bow" value=5 />
				No <input type="radio" name="bow" value=0 /><br>
	Stern: Yes<input type="radio" name="stern" value=5 />
				No<input type="radio" name="stern" value=0 />
</form>
<button onclick="outputsize()">Submit</button>
<script>
				
function outputsize() {
	var x,y,b,s,sizes;

	x=document.getElementById("form1") ;
	y=x.elements["sizes"].value;
	b=x.elements["bow"].value;
	s=x.elements["stern"].value;
	document.getElementById("demo").innerHTML=(y * 2+b+s);

}

</script> 

<h1 id="demo"></h1>
</body>
</html>

#2

maybe use something like parseInt ?
https://www.w3schools.com/jsref/jsref_parseint.asp


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

Thank you. I was wondering how to make the post viewable.


#5

You could also use the Number function to convert strings to numbers. You need to convert the input values because they are strings.

	y= Number(x.elements["sizes"].value);
	b= Number(x.elements["bow"].value);
	s= Number(x.elements["stern"].value);

#6

The Number Function did the trick. I was at a lost, but that makes complete sense.. Thank you so much for the helpful advice.


#7

Thank you for your suggestion. Using the Number Function was able to get me the result I was looking for.