|
> Stuff > Lucy's Portfolio! > Javascript Example 7
Find the maximum of this equation: y = 11 + 6*x - x*x
- Create a table with 4 rows and 2 columns in a form
- The rows contain the labels x, y, max_x, max_y and the appropriate input boxes.
- Set max_y to a big negative number e.g. -100.
- Use a for loop to iterate x between 0 and 10
- Inside the loop
- Calculate the function listed above.
- Use an if statement to work out whether y is bigger than max_y and if it is set max_y to y and max_x to x.
- Display the values of x, y, max_x and max_y in the input boxes and in an alert box
- After the loop clearly display the answer:
- The maximum value of the equation ? is ?, occurring when x = ?'
I'm not entirely sure where this example went, but I'll find it :o)
|