SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: i<5

  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    i<5

    3,6,9,12,15,18,21,24,...
    4,8,12,16,20,24,...

    I want message box displays 12.
    Code:
      
    <script type="text/javascript">
    // ortak katların en k&#252;&#231;&#252;ğ&#252;
    Math.leastCommonMultiplier=function(num1,num2){
    for(var i=2; i<5; i++)  if(( i*num1)&#37;num2 ==0) {var same =( i*num1); break;}
    return same;
    }
    
    var n = Math.leastCommonMultiplier(3,4);
    alert(n);  // 12
    var m=Math.leastCommonMultiplier(7,12)
    alert(m);  // returns undefined. it must display 84;
    
    </script>
    m must be 84;
    If I write i<15, message box displays 84.

    I want to write something else instead of i<5
    I try
    for(var i=2; ( i*num1)%num2 !=0; i++) {
    but it returns undefined.
    What can I do? Thanks...
    Last edited by muazzez; Apr 12, 2008 at 02:24.
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The variable same will only have a value if the if in the for loop is true. It will otherwise be undefined.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Math.okek(arguments0,arguments1,arguments2,arguments3, ...argumentsN);

    I want to call the function like this:
    Math.okek(2,3,4,5);
    Math.okek(2,3,4,5,6,7);
    Math.okek(2,3,4,5,6,7,12,14);

    How to change the following code?
    Code:
     
    <script type="text/javascript">
    
    Math.okek=function(){
    
    var a0=arguments[0];
    for(var i=2;; i++)  {
    if((i*a0)&#37;arguments[1] ==0 && (i*a0)%arguments[2]==0  && (i*a0)%arguments[3]==0) {
    var result = ( i*a0) ; break;
    } 
    }
    return result;
    }
    
    var n = Math.okek(2,3,4,5);
    alert(n);  // 60
    
    </script>
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •