I am very new to Javascript and I was wondering if anyone could help me for what seems to be quite a simple question to anyone who knows anything about JS. My problem is that I am trying to change the value of my variables after declaring them but everytime I change their values they are set back to what they used to be when they got declared. If anyone could please explain how I could work my way around this problem it would be greatly appreciated, Here's my code if you want to see it:
//Anything before this doesn't matter for my question.
<td>
<p id="first"></p> <--- this prints the "first" var declared in the script bellow but is always equal to 1 even when the button is pressed
</td>
<th class="col-xs-1 align-middle text-center">
<div class="btn-group">
<a class="btn btn-default btn-sm btn-add-all" onclick="value_up(first);"> <--- this is the button that calls the function when pressed
<i class="fa fa-arrow-up"></i>
</a>
</div>
<script>
var first = 1; <--- this is where I declare my variable
document.getElementById("first").innerHTML = first; <--- Here's where I pass my variable to the <p> tags up above
</script>
</tbody>
</table>
</div>
</div>
</div>
<script>
function value_up(x) { <--- this is the function I am calling when I press the up button
x = x - 1;
console.log(x);
return (x);
}
</script>