# Javascript functions

1 .User enters a percentage in the textbox

``````<input id="num1"  type="textbox" placeholder="please enter marks in percentage" class="textbox"  pattern="^[0-9]*\$" >Maths/Maths lit</br><input id="num2"type="textbox" placeholder="please enter marks in percentage" class="textbox" >Home language</br>
``````
1. Percentage is converted to a score based on a guideline
``````var num1 = document.getElementById("num1").value;
if(num1 <=100 && num1 >=90){
let apsa = 15;

alert(num1 +"%" +  " = aps score for maths/math lit is:" + apsa );
} else if ( num1 <=89 && num1 >=80){

alert("aps score for maths/math lit is 13" );

}
else if ( num1 <=79 && num1 >=70){
alert("aps score for maths/math lit is 11" );

} else if ( num1 <=69 && num1 >=60){
alert("aps score for maths/math lit is 9" );

}else if ( num1 <=59 && num1 >=50){
alert("aps score for maths/math lit is 7" );}
else if ( num1 <=49 && num1 >=40){
alert("aps score for maths/math lit is 5" );}

else if ( num1 <=39 && num1 >=30){
alert("aps score for maths/math lit is 3" );}

else if ( num1 <=29 && num1 >=20){
alert("aps score for maths/math lit is 1" );}

else if ( num1  < 20){
alert("aps score for maths/math lit is 0" );}

var num2 =document.getElementById("num2").value;

if(num2 <=100 && num2 >=90){
let apsa = 15 ;

alert("aps score for Home language/ eng 1st additional language  is:" + apsa );
} else if ( num2 <=89 && num2 >=80){
alert(("aps score for Home language/ eng 1st additional language  is 13" ) );

}
else if (num2 <=79 && num2 >=70){
alert("aps score for Home language/ eng 1st additional language  is 11" );

} else if ( num2 <=69 && num2 >=60){
alert("aps score for Home language/ eng 1st additional language  is 9" );

} else if ( num2 <=59 && num2 >=50){
alert("aps score for Home language/ eng 1st additional language  is 7" );}
else if ( num2 <=49 && num2 >=40){
alert("aps score for Home language/ eng 1st additional language  is 5" );}

else if ( num2 <=39 && num2 >=30){
alert("aps score for Home language/ eng 1st additional language  is 3" );}

else if ( num2 <=29 && num2 >=20){

else if ( num2  < 20){
alert("aps score for Home language/ eng 1st additional language  is 0" );}

``````
1. I want to add up the two scores for example if the user enters 95 and 95, the total will be 30.
``````my issue is storing the apsa from the if else statement and adding it up and printing it to the user.
``````

I am new to coding and trying to figure this out

1 Like