/    Sign up×
Community /Pin to ProfileBookmark

Why Won’t My Java Run Properly

Can anyone tell me why the result of the javascript doesn’t output into the h2 tags. This is my second day of coding and any help would be much appreciated….thanks

HTML
<!DOCTYPE html>
<html>
<head>
<title>Goal Calculator</title>
<link rel=”stylesheet” href=”styles.css”>
<script>
function calculate() {
var sbal = document.getElementById(‘sbal’).value;
var goal = document.getElementById(‘goal’).value;
var exp = document.getElementById(‘exp’).value;
var accben = document.getElementById(‘accben’).value;
var main = ((goal – (sbal – accben)) / 12 );
var result = (main + exp).tofixed(2);
payment = payment.toString().replace(/B(?=(d{3})+(?!d))/g, “,”);
document.getElementById(‘payment’).innerHTML = “Monthly Payment = $”+payment;
}

</script>

</head>
<body>
<div class=”wrapper”>
<div class=”contact-form”>
<div class=”input-fields” id=”calculate-form”>
<div class=”drop”>
<label>Time Period</label>
<select id = “myList”>
<option value = “1”>Week</option>
<option value = “2”>Fortnight</option>
<option value = “3”>Year</option>
</select>
</div>
<input id=”sbal” class=”input” type=”number” placeholder=”Starting Balance”>
<input id=”goal” class=”input” type=”number” placeholder=”Overall Goal”>
<input id=”exp” class=”input” type=”number” placeholder=”Expenditure”>
<input id=”accben” class=”input” type=”number” placeholder=”Account Benchmark”>
<h2 id=”payment”></h2>
</div>
</div>
</div>
</div>
<div>
<button class=”btn” id=”footer” onclick=”calculate()”>Submit</button>
</div>
</body>
</html>

CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
outline: none;
font-family: cursive, sans-serif;
}

body{
background: url(‘flex.png’) no-repeat top center;
background-size: cover;
height: 100vh;
}

.logo img{
position: relative;
left: 25px;
padding: 0px;
float: left;
width: 150px;
height: auto;
margin-top:10px;
margin-left: 10px;

}

.wrapper{
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
padding: 0 20px;
}

.drop{
position: relative;
left:15px;
}

.myList:hover {
background-color: rgba(0,0,0,0.1);
}

select{
background-color: transparent;
border: transparent;
position: relative;
left: 40px;
color: #fff;
cursor: pointer;
}

select:active {
background-color: transparent;
}

label {
position: relative;
left: 15px;
color: #fff;
}

.contact-form{
display: flex;
max-width: 450px;
margin: 0 auto;
background: rgba(0,0,0,0.8);
padding: 30px;
border: 5px solid #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

.input-fields{
position: relative;
left: 115px;
display: flex;
flex-direction: column;
margin-right: 4%;
position: relative;
}

.input-fields,
.msg{
width: 44%;
}

.input-fields .input,
textarea{
margin: 10px 0;
background: transparent;
border: 0px;
border-bottom: 2px solid #fff;
padding: 10px;
color: #fff;
width: 100%;
}

h2 {
text-align: center;
position: relative;
top: 15px;
color: #fff;
}

#footer {
position: absolute;
bottom: 0px;
width: 100%;
}

.btn {
background: #000;
text-align: center;
padding: 15px;
border-radius: 5px;
border-style: none;
color: #fff;
cursor: pointer;
text-transform: uppercase;
}

a {
text-decoration: none;
color: #fff;
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@khalby786Dec 26.2019 — > @T1Alpha#1612206 payment = payment.toString().replace(/B(?=(d{3})+(?!d))/g, ",");

I think it would be better to store the payment algorithm values into a new variable, rather than re-assigning it to the same variable!
×

Success!

Help @T1Alpha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...