Guessing Game Using Loops And If Statements

Dec 5, 2010

We have to create a number guessing game with a random number between 1 and 50. With a loop that runs exactly 10 times or until you get the number and gives hints that say guess higher or lower. I don't know what I am doing wrong this wont work at all. I am generally lost?
lab14a_KENTDL.html (3.48K)
Number of downloads: 52

View 1 Replies


ADVERTISEMENT

Put Choices In Guessing Game

Apr 15, 2011

how can i put choices in a guessing game. choices such as a,b, c, and d. And if the answer of the player is correct, the game will proceed to level 2, else game over.

View 1 Replies View Related

Help With # Statements

Nov 12, 2005

I am sure if I searched long enough I could find the answer, but to save time I would appreciate help with the # statements, such as #include, #csstopmenu, etc which I find in the scripts here and elsewhere. I know that #include is used with shtml to include another html page. What are the others? Is there a definitive list, and if so where can I find it?

View 2 Replies View Related

Nested If Then Else Statements

Oct 9, 2005

This code uses a nested IF statement to put a pack of cards into an array of records.
But for some reason the cards arn't going in.. like.. at all? I've put a document.write piece of code at end to display the card in the first slot and [object Object] appears? Code:

View 2 Replies View Related

JS If Statements Are Not Working?

Mar 25, 2011

I apologise for any complexity of the following script, but what I am trying to achieve is

1.) At 6:51 am, the image sunrise.png is written as the background of #wrap

2.) At 12:04 midnight through 12:07 midnight, the background of #wrap is green.png then

3.) Then, at a random time at night that is not 6:51 am nor in-between 12:04 midnight & 12:07 midnight, the background of #wrap is set as aurora.png

This is the code of if statments that I wrote to achieve it:

[Code]...

View 2 Replies View Related

Case Statements In Javascript

Apr 16, 2007

So I have some code like:

if (document.Insurance.State.selectedIndex == 1)
{
ifIll();
}
else if (document.Insurance.State.selectedIndex == 2)
{
elseKan();
}
else if (document.Insurance.State.selectedIndex == 3)
{
elseInd();
}

I am trying to replace the if-else statements with case statement as
follows:

var index = document.Insurance.State.selectedIndex;

switch (index)
{
case 1:
ifIll()
break
case 2:
elseKan()
break
case 3: elseInd()
break
}

This code doesn't work ! Am I missing something here?

View 17 Replies View Related

Comparing Multiple AND And OR Statements?

Mar 5, 2009

I need to test the contents of three fields to validate which contain text, and based on the results, set additional variables. I'm sure this is falling off the log simple, and I got it to work in PHP, but am having problems getting the syntax correct in Javascript.

In a nutshell, if a front AND a rear msg is entered, the price is $115, else the price is $80. I'm sure there's an easier way to code this than what I've done, but I don't know how to correctly perform several && and || in the same comparison.

Here's the PHP...

function notEmpty(){
var FrontMsgTxtTop = document.getElementById('FrontMsgTxtTop').value;
var FrontMsgTxtBottom = document.getElementById('FrontMsgTxtBottom').value;
var RearMsgTxt = document.getElementById('RearMsgTxt').value;

[Code]....

View 3 Replies View Related

Trying To Get Two Javascript Statements To Work Together...

Nov 28, 2001

<script language="javascript">
<!--
self.location.href='#add'
document.addform.txtTitle.focus();
//-->
</script>

the self.location.href='#add' goes to a html anchor on the page, and the focus is supposed to set the cursor inside the first textbox when the statement is run.

if i run it as is, it will go to the anchor like its supposed to, but won't put the cursor in the textbox. if i comment out the first statement, it will put the focus on the textbox.

View 3 Replies View Related

Using Conditional Statements In Functions

Oct 4, 2010

I have a very simple script that generates a prompt window. Instead of using a default text, I have left the text field empty. However, I would like a default message to display in the pop up window if the user does not enter a value in the prompt box before clicking okay. I tried adding a conditional statement but the default text does not write in the pop up window.

Here is the code:
Code:
function promptBox(){
var message = prompt("Who is your favorite Hollywood Star?", "");
newWindow = window.open('','','width=800,height=600');
newWindow.document.write(message);
newWindow.focus();
if ((prompt) == null);
document.write("No Value Entered");
}

View 5 Replies View Related

Any Way To Merge Two OnClick Statements

Apr 5, 2010

I try to figure out how I can merge two onclick in one: The one is opening a "lightbox" div with a fullsize view. Now I would like to count this click with loading a site in an iframe. I am not that known in javascript, therefore my question: Is it possible?

This would load the iframe:
PHP Code:
onclick=parent.fullsize.location='[URL]';

This is the onclick statement in the lightbox.js:
PHP Code:
anchor.onclick=self._genOpener(num)}var body=d.getElementsByTagName("body")[0];

Separated the both onclick are not working. How I can put them together in one onclick? I tried this, but it is not working:
PHP Code:
anchor.onclick=self._genOpener(num)}var body=d.getElementsByTagName("body")[0] && parent.fullsize.location='[URL]';

View 1 Replies View Related

JQuery :: Not Calling Elements In If Statements?

Mar 1, 2010

The jQuery isn't working when calling elements placed in conditional statements. My sample code is shown below. This code works beautiful if the if/else conditions aren't there. What is the problem? Is there something wrong with my code? Is there a workaround? I absolutely need to use a conditional statement in my production code.

<?php
$test = 'true';
print "

[code]....

View 5 Replies View Related

IE Does Not Recognize Document.Write Statements

Sep 22, 2009

I have a series of videos which must be loaded dynamically on their pages which then get loaded into an iframe. I need to be able to load these videos using variables for the width and height. It's imperative that I use variables as the sizes of the movies will be determined by the user's resolution.

Here's the code I'm currently using <script type="text/javascript">
var dimW = screen.width;
var dimH = screen.height;
var w1 = dimW.toString();
var h1 = dimH.toString();

document.write('<OBJECT ID="Player" width="'+w1+'" height="'+h1+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style=border:0px;">
'); .....

I'm developing in xhtml so naturally, IE doesn't recognize the document.write statements and the page comes up blank in IE. It works flawlessly in FireFox (as expected). So, I need to replace the document.write statements with something else while still being able to pass variables for the movie objects height & width.

I've tried this code: <script type="text/javascript">
//alert("The beginning");
var dimW = window.innerWidth;
var dimH = window.innerHeight;
var w1 = dimW.toString();
var h1 = dimH.toString(); .....
document.getElementById('mediaPlayer').appendChild(theNewMovie);
</script>. I then have a <td> with the id of "mediaPlayer" but nothing is showing up. Most likely because I'm still fairly new to javascript and am probably forgetting or overlooking something.

View 18 Replies View Related

Use Variables In Document.form.Q[0].value Statements

Oct 7, 2009

I am trying to write a multiple-choice quiz for my chemistry class where ten questions are selected randomly from a block of about 100; then I want the students to click a button and grade their quiz. I have stored the questions in an array named Q and each radio button has a name property corresponding to the array entry (the buttons in Q[1] have the name Q1, etc.). I generate the exam in the body of the page between form tags using a document.write statement and all of the questions and buttons appear properly. I cannot, however, figure out how to get the value of the button that has been checked for the randomly selected questions.

As the questions are selected, I record the question number as a variable; for example �Qnumber1 = Q(random_num)�. The variable does, in fact, have the proper value (for example Q1) but when I try to read the value of the radio buttons in the Q1 set using:

document.form1.Qnumber1[0].value

it doesnt work!

View 6 Replies View Related

Radio Button If Statements Not Working?

Jan 26, 2011

I have this calculator function I made to do some simple math and output the solution in a field on a form. I had it working great until I introduced a radio button. There are no errors and the total is still outputted but the number is off and if I change the radio to the other option it doesn't change the total. Here is my code,

function calculateBudget()
{
var i;
var list = 0;
var listcost = document.getElementsByName('form[listcost]');

[Code]....

View 13 Replies View Related

Multiple IF Statements In Form Validations

Jan 15, 2009

This is what i'm working with now but can only get one function to validate. This is the script I have so far. With credit going to pmw57 Need to be able to validate more than just one function.

<script language="javascript" type="text/javascript">
var form = document.getElementById('healthwiseorder');
form.onsubmit = validateForm;
function validateForm() {

[Code]....

View 6 Replies View Related

Conditional Operators Versus If Else Statements

Apr 28, 2011

I'd like to ask if it is possible to use conditional operators
var = condition ? var1 : var 2
To do the same job as the if-else statements I wrote in red below:
<p id="text">change text colour</p>
<br />
<a onclick="allsorting();">sort in both ascending & descending orders</a>
<div></div>
<script>
/* if & else */
function changetext(){
document.getElementById('text').onclick = function (){
swapcolour(this);
}}
function swapcolour(text){
if(text.style.color == 'black'){
text.style.color = 'red';
} else {text.style.color = 'black'}
} window.onload = changetext;
</script>

View 25 Replies View Related

While Loops

Nov 4, 2007

i am trying to do but I have no clue how to write it. Im trying to write a while loop that prints out all of the multiples of 5 between 10 and 95. I just need to know how to write the while loop i got everything else.

View 1 Replies View Related

Switch Statements And Variables - Creating Bars?

Apr 18, 2011

I'm having some trouble with the Switch Statements. My program runs without it so I know that the problem is here. I believe the logic is sound so it may be due to incorrect syntax. The purpose of this function is to create bars, and the length of the bars is determined by the value of the "percent" variable (which is working fine) in the For loop after the Switch statements. The variable, "partyType" contains any of the text strings, such as "I", "D", etc.

function createBar(partyType,percent){
var barText;
switch(partyType){
case "D":
barText="<td class='dem'></td>";
break;
case "R":
barText="<td class='rep'></td>";
break;
case "I":
barText="<td class='ind'></td>";
break;
case "G":
barText="<td class='green'></td>";
break;
case "L":
barText="<td class='lib'></td>";
break;
default: document.write("hi");
}
for(var i=1; i<percent; i++){
document.write(barText);
}}}

View 1 Replies View Related

Checkboard Pattern - Three Output Statements To Display

Oct 24, 2009

This code not sure what the final result should be.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 StrictEN" [URL]">
<!-- Exercise 7.25 Solution -->
<html xmlns = "[URL]">
<head>
<title>Solution 7.25</title>
<script type = "text/javascript">
<!--
var side = 8;
var row;
document.writeln( "<pre>");
while(side>=1){
row = 8
if (side % 2 != 0)
document.write(" ")
while(row >= 1){
document.write("* ")
row -= 1;
} end while
document.writeln();
side -= 1;
} end while
document.writeln("</pre>")
-->
</script></head><body>
<p>Click Refresh (or Reload) to run this script again.</p>
</body></html>

This what I got when I ran the script. Click Refresh (or Reload) to run this script again. These ere the constraints of the assignment. Write a script that outputs XHTML text that displays the checkerboard pattern: Your program may use only three output statements to display the pattern:
1. Only one document. write( "* " );
2. Only one document. write( " " );
3. and Only one document. writeln(); writes a newline character
You may use XHTML tags (e. g., < pre>) for alignment purposes.
[Hint: Repetition structures are required in this exercise.]

View 4 Replies View Related

Multiple Loops

Feb 6, 2006

I'm my script I've three loops processing a very huge data file. IE & Firefox show a message box after some time saying my script could be infinite looping and give me a chance to stop it.

Is there a way to prevent this dialog box to show up? I'm writing a script used only on a intranet and the final customer should not see the message box.

View 6 Replies View Related

Question About Loops

Jan 12, 2007

Hi, I want to have something like this:

function callme1() {
alert('somestuff');
}

function callme2() {
alert('somestuff');
}

function callme3() {
alert('somestuff');
}

function callme4() {
alert('somestuff');
}

etc.

except, it's going to be created in a loop, like

var x=0;
while (x<10) {

function callme[x]() {
alert('somestuff');
}

x++
}

So, out of that I would like to get 10 callme(1-10 or A-J) functions...
I guess I am lost which way to build this with the placement & parsing
of the variables.

View 3 Replies View Related

How To Break Out Of All Loops

Jun 6, 2009

Is it possible, when you have a loop in a loop, that when the inner loop reaches a certain point, it breaks out of both loops? For example:

[Code]....

The code above will break out of the (b=0;b<=10;b++) loop when b==5, but it will continue to do the a loop. not putting the first loop at all or making the first loop stop at 1): Is there a way to break out of both loops when the if condition is met? (I only ask that you not give a work-around because what I have in mind is much more complicated than this)

View 3 Replies View Related

Using SetInterval In Loops

Dec 15, 2007

i'm scratching my head over achieving similar results with setInterval() function, and how I can keep it from looping infinitely.

I want to do something like this:
var i = 0;
var endTime = now + ((1000*60)*2); // 2 minutes after now
while (now <=endTime) {
i = i + 1;
now = new Date().getTime();
}
document.write("total iterations: " + i);

however you can't do this because of lag issues, so i'll settle for using setinterval on its smallest interval of a millisecond, here is my attempt to translate the above to a setinterval solution:
var endTime = now + ((1000*60)*2); // 2 minutes after now
var intervalID = setInterval(loopFunc(endTime),1);
function loopFunc(endTime,intervalID) {
if (new Date().getTime() <= endTime) {
i = i + 1;
} else {
clearInterval(intervalID);
}}

as you can see I have prolbems figuring out how to stop the interval from continuing to iterate, and passing the interval id, I'm clueless Also I'm clueless on echoing the total iterations via this method.

View 4 Replies View Related

Getting Averages From Loops?

Nov 8, 2009

I want to get averages from a for loop. Let's say I had a # of exams and in that loop I wanted to add the exams up and calculate the average. How would I go about doing this? Is this even possible in a for loop?

View 1 Replies View Related

Using While Loops Incrementer?

Jul 26, 2009

If I were to have a script:

Code JavaScript:
var numbers = [1, 2, 3, 4, 5];
var incrementer = 0;
while (incrementer < numbers.length)
{

[Code]...

View 1 Replies View Related

Cliping A String Without Loops

Jul 20, 2005

I have got a span inside a td of a table. i am trying to clip the
string that exceeds the length of the td and then put three dots
("...") after it so it will show that the text was clipped and when
the mouse hovers above it, it will show the title. now i have managed
to do all the above by puting a span inside the td with the style
overflow:hidden and it all works fine. to add the three dots i have to
clip the string to ten pixels below the length of the td and then add
the dots. i can do it by slicing the string in "string.length-1" each
time and then get the new length of the string with offsetWidth, and
when getting to the right length - add the dots. the problem is that
the slicing is done in a "while" loop, and when having a very long
table it takes too much time. the question is if there is any methods
of clipping the string by pixels or any other method that will shorten
the run time of the script.

p.s.
i tried also having another span with the three dots that is
display:none and when the length exceeds the span length (the length
of the span is set to the td-10px) i change the display to block, but
the second span keeps on droping a line which is not good for me.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved