<html>
<title>JavaScript</title>
<meta http-equiv="content-type" content="text/hmtl"; charset="UTF-8">
<script language="JavaScript">
function multiple5(){
var num1, num2, num3=5, num4="", mult=5, result;
num1=parseInt(prompt("Introduce un nĂşmero:",""));
if(num1>>0){
num2=num1;
num1=1;
for (num1=num1;num2>=num1;num1++){
result=num1%mult;
if(result==0){
num3=num3+mult;
num4=num3;
//text();
}
}
alert(num4+" ");
}else{
alert("Lo siento pero el nĂşmero introducido no es mayor a 0");
}
}
</script>
<form name="formulario" method="post" action="">
<input type="button" onClick="multiple5()" value="Multiples de 5">
</form>
</html>
If there is an easier way to simplify it, please tell me so it would help me a lot, I’ve been doing this for more than 3 hours, and I can’t figure out how the hell to fix it, the output is just all the multiples added giving 30 if you put 25
>Solution :
function showMultiplesOf5() {
var num = parseInt(prompt("Enter a number:"));
if (num > 0) {
var multiples = "";
for (var i = 5; i <= num; i += 5) {
multiples += i + " ";
}
alert("Multiples of 5: " + multiples);
} else {
alert("Sorry, the number entered is not greater than 0.");
}
}