Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get the multiples of the number 5 in a single popup window when pressing a button?

<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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.");
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading