Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 23rd, 2012, 04:43 AM
 qwertyoone
Registered User

Join Date: Sep 2012
Posts: 1
Time spent in forums: 3 m 49 sec
Reputation Power: 0
Sum of same variables in a repeated function

<!DOCTYPE html>
<html>
<body>
<p id="q"></p>
<script>
function theFunction3()
{
var x=Math.floor((Math.random()*20)+1);
var y=Math.floor((Math.random()*20)+1);
var score;
var attempt;
var Tattempt=sum(attempt)

if (Tattempt<11)
{
prompt(x + "x" + y + "=?","");
var name=prompt(x + "x" + y + "=?","");
if (name=x*y)
{
score=1;
attempt=1;
}
else if (name!=x*y)
{
score=0;
attempt=1;
}
else
{
var z="You've got" + sum(score) + "Out of 10!";
document.getElementById("q").innerHTML=z
}
}
}
</script>
</body>
</html>

____________________________________________________________
1. Please state any errors in this code. (If any)
2. I want to create a math quiz on multiplication using JavaScript. Questions are to be randomly generated and separately displayed in a prompt box. The user must recieve a score out of ten. A prompt box for the result is optional.

#2
September 23rd, 2012, 03:58 PM
 Kravvitz

Join Date: Jul 2004
Location: USA
Posts: 20,099
Time spent in forums: 6 Months 6 Days 18 h 41 m 17 sec
Reputation Power: 4195
Welcome to DevShed Forums, qwertyoone.

This wouldn't happen to be a homework assignment would it?

What is the purpose of the "sum" function?

Why do you use prompt() to ask the same question twice?
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

 Viewing: Dev Shed Forums > Web Design > JavaScript Development > Sum of same variables in a repeated function