1 Replies - 504 Views - Last Post: 24 September 2012 - 10:32 AM

#1 mindiapolis  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 175
  • Joined: 31-October 11

JAVASCRIPT QUESTION

Posted 24 September 2012 - 10:09 AM

can someone please help me understand why the correctAnswer function is not displaying the message for question 1?

<!doctype html>
<html lang="en">
<head>
 <title>CINS 257 Exam 1</title>
 <meta charset="utf-8" />
 <link rel="stylesheet" href="style.css" />
 <style>
        #wrapper       {       margin: auto;
                                      width: 960px;
                               }
        li                     {       display: inline; }
</style>
<script>
	function correctAnswer(semicolon_0, semicolon_1) { 
		if(document.getElementById('semicolon_0').checked) {
			alert ("That is correct!");  	
		}else if(document.getElementById('semicolon_1').checked) {
			alert ("That is not correct!"); 
		}
	}
</script>
</head>
<body>
<section id="wrapper">
<header>
  <h1>CINS 257 Exam 1</h1>
  <h2>Mindy Thomas </h2>
</header>
<p>Is a semi-colon used to end a javascript statement? </p>
  <p>
	  <label>
	    <input type="radio" name="semicolon" value="Yes" id="semicolon_0" onclick="correctAnswer(semicolon_0, semicolon_1">  
	    Yes</label>
	  <br>
	  <label>
	    <input type="radio" name="semicolon" value="No" id="semicolon_1">
	    No</label>
	  <br>
  </p>
  <p>How do you add a comment in Javascript?</p>
  <p>
    <label>
      <input type="radio" name="comment" value=""/" id="comment_0">
      "/</label>
    <br>
    <label>
      <input type="radio" name="comment" value="??" id="comment_1">
      ??</label>
    <br>
    <label>
      <input type="radio" name="comment" value="// or /*  */" id="comment_2">
      // or /*  */</label>
    <br>
    <label>
      <input type="radio" name="comment" value=";." id="comment_3">
      ;.</label>
    <br>
  </p>
  <p>How do you add an element into an array? </p>
  <p>
    <label>
      <input type="radio" name="add" value="drinkArray.push('Pepsi');" id="add_0">
      drinkArray.push('Pepsi');</label>
    <br>
    <label>
      <input type="radio" name="add" value="drink.push('Pepsi');" id="add_1">
      drink.push('Pepsi');</label>
    <br>
    <label>
      <input type="radio" name="add" value="I don't know.  What is an array anyway?  " id="add_2">
      I don't know.  What is an array anyway? </label>
    <br>
  </p>
  <p>Which one of these is the NOT operator? </p>
  <p>
    <label>
      <input type="radio" name="Not " value="$" id="Not_0">
      $</label>
    <br>
    <label>
      <input type="radio" name="Not " value="@" id="Not_1">
      @</label>
    <br>
    <label>
      <input type="radio" name="Not " value="!" id="Not_2">
      !</label>
    <br>
    <label>
      <input type="radio" name="Not " value="%" id="Not_3">
      %</label>
    <br>
  </p>
  <p>How do you declare a javascript variable? </p>
  <p>
    <label>
      <input type="radio" name="declare " value="$" id="declare_0">
      $</label>
    <br>
    <label>
      <input type="radio" name="declare " value="Variable =" id="declare_1">
      Variable =</label>
    <br>
    <label>
      <input type="radio" name="declare " value="Hmm, what do you think?  " id="declare_2">
      Hmm, what do you think? </label>
    <br>
    <label>
      <input type="radio" name="declare " value="var" id="declare_3">
      var</label>
    <br>
  </p>
<footer>
  <ul>
    <li>Ivy Tech Community College</li>
    <li>3800 N. Anthony Blvd.</li>
    <li>Fort Wayne, IN 46805</li>
    </ul>
</footer>
</section>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: JAVASCRIPT QUESTION

#2 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: JAVASCRIPT QUESTION

Posted 24 September 2012 - 10:32 AM

You should start by looking at the Error Console. It can tell you useful stuff like this:

Attached Image


Also, I should probably point out that the semicolon_0 and semicolon_1 parameters for your checkAnswer function are not being used in that code. The code in your function is ignoring them, instead using strings matching their names for the getElementById calls. The values you supply for those parameters in the <input onclick> code are also invalid. As far as I can tell, no global variables named like that exist. - Unless you're trying to pass the elements with those IDs to the function, which would be ill adviced. Better pass strings and use the getElementById function, kind of like you do.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1