Javascript Help

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

Javascript Help
  1. Unread #1 - Dec 28, 2011 at 9:29 PM
  2. Noam
    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

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

    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?
     
  3. Unread #2 - Dec 29, 2011 at 10:03 PM
  4. Noam
    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

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

    Javascript Help

    Bump.
     
  5. Unread #3 - Dec 29, 2011 at 10:19 PM
  6. iJava
    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    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.
     
  7. Unread #4 - Dec 30, 2011 at 3:04 AM
  8. Noam
    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

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

    Javascript Help

    Yeah I should probably say I can read most programming languages no problem But that's not nested for loops
     
  9. Unread #5 - Dec 30, 2011 at 11:59 AM
  10. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    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
    
     
  11. Unread #6 - Dec 30, 2011 at 9:39 PM
  12. Noam
    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

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

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

Users viewing this thread
1 guest


 
 
Adblock breaks this site