Thursday, July 31, 2008

Week 03 HW1 -- WBP

Homework part 1
Was ridiculous. This assignment deffinetly requires you, to think out side of the box!

The assignment is to ask the User to for a Number 1-10.
Then depending on what number they give you, you need to print out a Number pyramid.
So if the user gives you 4
you will print out
1
22
333
4444

And ect... This will go on and on!

The trick to this assignment is to use two for loops.
Start out by prompting the user for a number
Have what ever value they give you, be turned into a variable...

An example of this would be
var userInp = prompt("Please Give me a Number");

Next you need to parse their input into a Real Number value
So the overall is to create a new variable, that takes the users input and parses it into a number!
This can be done by using
parseInt();

var userNum = parseInt(what goes here?);

Next we create a for loop that will count until we reach the userNum

for (var ind= 1; ind <= userNum; ind++){
//In here we document write our ind
document.write(ind);
}

This will print out all the numbers before the user input
So how do we create the pyramid.
This is smartest think about it by using pseudo programming.

We use the same process as our first loop. But we in bed it in our loop. So we create a second for loop.

But we need to place it somewhere. How bout in the first loop.
notice what were conflicting...

for (var ind2= 1; ind2 < ind; ind2++){
document.write(ind);
}

ind vers ind2
This way they can corresponds with each other.

thats it.
Theres one more line to enter and thats
which writes an html break



Figure out where all these lines go, and you completed this weeks first homework assignment!

:D

-Franky

1 comment:

kateF said...

ridiculous, huh?....

awesome commenting though. on all of your work. bravo!