Adblock breaks this site

Javascript Help

Discussion in 'Web Programming' started by Noam, Dec 28, 2011.

  1. Noam

    Noam Apostle of the Setting Sun
    $50 USD Donor New Competition Winner

    Joined:
    Jul 27, 2011
    Posts:
    2,993
    Referrals:
    1
    Sythe Gold:
    0
    Discord Unique ID:
    688859853535313930
    Discord Username:
    sarbaz#8969
    Two Factor Authentication User Gohan has AIDS
    Javascript Help

    I have given up here. I can't see how this would logically work. I had done it using a switch case statement, but the guy said that it didn't use nested loops :(. I cant use objects or any of that shit here, only conditional statements and loops.
    Any help?
     
  2. Noam

    Noam Apostle of the Setting Sun
    $50 USD Donor New Competition Winner

    Joined:
    Jul 27, 2011
    Posts:
    2,993
    Referrals:
    1
    Sythe Gold:
    0
    Discord Unique ID:
    688859853535313930
    Discord Username:
    sarbaz#8969
    Two Factor Authentication User Gohan has AIDS
    Javascript Help

    Bump.
     
  3. iJava

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441
    Javascript Help

    Don't know JavaScript however in Java you would do :

    Code:
     int numLines = 13;
            for (int i = 0; i < numLines; i++) {
                if (i == 1) {
                    System.out.println("*");
                }
                if(i == 2) {
                    System.out.println("**");
                }
            }
    Yeah I know that code is messy and not sure if you're allowed to do that but ehh.
     
  4. Noam

    Noam Apostle of the Setting Sun
    $50 USD Donor New Competition Winner

    Joined:
    Jul 27, 2011
    Posts:
    2,993
    Referrals:
    1
    Sythe Gold:
    0
    Discord Unique ID:
    688859853535313930
    Discord Username:
    sarbaz#8969
    Two Factor Authentication User Gohan has AIDS
    Javascript Help

    Yeah I should probably say I can read most programming languages no problem But that's not nested for loops
     
  5. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Javascript Help

    I don't want to completely do your homework for you so here's how I've done it in Python to help you understand where the nested for loop comes in (to print the right number of stars) and how you decide whether you have reached the halfway point or not since this affects how many you are printing. Doing this the right way allows you to do it for any number of rows specified.

    Code:
    rows = 13
    
    half = (rows + 1) / 2
    
    for i in range(1, rows+1):
    
       if i > half:
          starCount = half - (i - half)
       else:
          starCount = i
       for star in range(0, starCount):
          print '*',
       print
    
     
  6. Noam

    Noam Apostle of the Setting Sun
    $50 USD Donor New Competition Winner

    Joined:
    Jul 27, 2011
    Posts:
    2,993
    Referrals:
    1
    Sythe Gold:
    0
    Discord Unique ID:
    688859853535313930
    Discord Username:
    sarbaz#8969
    Two Factor Authentication User Gohan has AIDS
    Javascript Help

    Ah I didn;t think of it like that. It makes sense now.
     
< Quick Question: Best Script for blogging, posting youtube videos, members page | Website template Seller! >


 
 
Adblock breaks this site