/    Sign up×
Community /Pin to ProfileBookmark

Need Help ASAP!!

Hey! I’m new to this whole JavaScript thing and I have to do a project for class and i can’t figure it out. here’s what it is. if any one can help that would awesome!

Concepts covered – JavaScript – For Loop & While Loops

Script 1:
Write a script that will have a user play “guess a number” with a computer. The computer will pick a number between 1 and 100. The user should then be prompted to guess a number. If the user guesses too high, print out a message stating that the number is too high. If the user guesses too low, print out a message stating that the number is too low. If the user guesses the number, print out a message stating that they won and then end the game.

Use: Javascript prompts and alerts to communicate with the user.

Use: To have the computer simulate guessing a number you will need to use a built in random number generator.

Math.floor(1 + Math.random() * 100) will produce a number from 1 to 100 – assign the result to a variable

Use: an endless while loop: while(1)
to continue prompting the user until they get the correct answer

Use: a “break” statement to get out of the while loop when the correct answer has been guessed

Script 2:
Use nested for loops to create an XHTML table which represents the multiplication times table. Be sure to print out the program using <table>.

example:

1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 16 21 24 27 30
4 …
5 …
6 …
7 …
8 …
9 …
10 20 30 40 50 60 70 80 90 100

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@MaydayNov 03.2008 — Maybe if you post what you've gotten done so far someone can give you a hint as to where your error(s) might be.
Copy linkTweet thisAlerts:
@Cassandrak23authorNov 03.2008 — i dont really have much done cause i'm not sure where to start.
Copy linkTweet thisAlerts:
@Cassandrak23authorNov 03.2008 — but here is something we did in class that i can't seem to get working...

<html>

<title> Array Practice</title>

<script>

function doArrayStuff()

{

var array1 = new Array(6)

array1[0] = 0;
array1[1] = 0;
array1[2] = 0;
array1[3] = 0;
array1[4] = 0;
array1[5] = 0;

for (var x= 0; x < 6; x++)
{
array1[x] = 0
}


document.writeln("<table>");
document.writeln("<thead><th>Subscript</th> <th>Value</th></thead>");

for (var i = 0; i < array1.length; i++>
{
//alert("hello");
document.writeln("<tr><td>" + i + "</td>");
document.writeln("<td>" + array1[i] + "</td></tr>");
}
document.writeln("</table>");
}

</script>


<body onload="doArrayStuff();">

</body>

</html>
Copy linkTweet thisAlerts:
@FangNov 03.2008 — for (var i = 0; i &lt; array1.length; i++[B][COLOR="Red"]&gt;[/COLOR][/B]
Copy linkTweet thisAlerts:
@ZeroKilledNov 03.2008 — sorry, i was too slow. however, that previous script should give you the idea for coding the second script assignment.
Copy linkTweet thisAlerts:
@Cassandrak23authorNov 05.2008 — <html>

<head>

<title> Guess a Number </title>

<script type = "text/javascript">



var number2;
number2 = (Math.floor(1 + Math.random() * 100));
do
{
var number 1;

number1 = window.prompt("guess a number (1-100):");

if(number1==number2)
{
document.writeln("<h1 styple = "color: blue"> You Win!</h1>");
}

if(number1>number2)
{
window.alert("Too High, Try Again");
}

if(number1<number2)
{
window.alert("Too Low, Try Again");
}
while(number1! =number2);
}


</script>

</head>

<body>

</body>

</html>
Copy linkTweet thisAlerts:
@ZeroKilledNov 05.2008 — few line where you have to do some correction:
<i>
</i>var number 1;
// there is a space within [i]number[/i] and [i]1[/i];

while(number1! =number2);
// there is a space in the operator !=

do{
.
.
.
while(...)
[color='red']}[/color]
// the while loop statement should be declared outside the [b]do[/b] block as follow:
do{
.
.
[color='red']}[/color]
while(...);
Copy linkTweet thisAlerts:
@Cassandrak23authorNov 10.2008 — Write JavaScript code that prompts a user to enter their grades for 10 assignments. Store the grades in an array. Use a loop and array subscripting to compute the average of the grades and find the high grade. Output your results.
Copy linkTweet thisAlerts:
@MaydayNov 10.2008 — Again, to get assistance, you should post what you have done and where you're stumped. People who post replies here have already handed in their homework assignments, and don't look forward to doing others' homework for them. :eek:

However, people are more than happy to point you in the right direction if you can show that you're trying to work it out yourself but have run into a snag. ?
×

Success!

Help @Cassandrak23 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...