• Log in or sign up for an account here: https://www.sythe.org/login

Javascript Help

Noam

Apostle of the Setting Sun

$50 USD Donor New
Competition Winner
Joined
Jul 27, 2011
Sythe Gold
0
Messages
2,993
Location
(0,0)
Two Factor Authentication User
Gohan has AIDS
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?
[FONT=arial,helvetica,sans-serif]Assignment 4a[/FONT]​
Create an XHTML document which includes a reference to an external JavaScript file. Include the code in this JavasScript file to print the following pattern:

*

* *
* * *
* * * *
* * * * *
* * * * * *

* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

(Hint: Use nested for or while loop)
Also,


  • [*]Include the dtd for XHTML transitional.
    [*]Title the web page “Conditional statements and Loops”
    [*]Save the JavaScript file as pattern_javascript.js
    [*]Save the XHTML document as 4a_statements_loops.html
 
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.
 
Two Factor Authentication User
Gohan has AIDS
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.
Yeah I should probably say I can read most programming languages no problem But that's not nested for loops
 
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
 
Two Factor Authentication User
Gohan has AIDS
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
Ah I didn;t think of it like that. It makes sense now.
 
Runescape Gamblingrunescape gambling
Back
Top