Reputation: 3
First of all, I would like to apologize since the following code has been written in Danish and might not make any sense to non-danish people.
I've written this piece of code: JSFiddle
I have a function that asks the user how many years the user wants to analyze:
function udregnAnalyseAr() {
var virksomhedsnavn = prompt("Hvad hedder den virksomhed du arbejder med?");
var analysear;
ar = parseFloat(prompt("Hvor mange analyseår er der?"));
if (ar <= 1.00) {
analysear = "Der er ikke tilstrækkeligt antal år til at lave en sammenlignende rentabilitetsanalyse.<br>";
}
else if (ar > 1.00){
analysear = "Der er blevet registreret " + ar + " regnskabsår.<br>";
}
else{
analysear = "Skriv svaret som en talværdi eksempel: 2<br>";
}
document.getElementById("analyseArId").innerHTML = "Din virksomhed er blevet registreret som ";
document.getElementById("analyseArId").innerHTML += virksomhedsnavn;
document.getElementById("analyseArId").innerHTML += ".<br>";
document.getElementById("analyseArId").innerHTML += analysear;
}
Later down I have another function that is supposed to write some text based on how many years the user has inputted and what value the user submitted in the second function. My issue is that my entire 3rd function doesn't execute for some reason, even when the if (ar <= 2.00) {}
is satisfied.
Thank you in advance
Upvotes: 0
Views: 54
Reputation: 2037
If ar
has a defined value, the third block (second else
) will never be executed because either the first one is executed (ar<=1.00) or the second one is executed (ar>1.00)
Upvotes: 1