/    Sign up×
Community /Pin to ProfileBookmark

A quiz Ive been working on

Any help would be appreciated, im kinda short on time and im BRAND new to javascripting and some of these questions are exactly straight from the text, they need an general idea of the material. A breif description of why the answer is what it is would be nice not necessary though..Im not a complete leecher I am very good with photoshop and i got some other things i might be able to help you with if you can spare me on this quiz..

please save any flaming, if you dont want to help you dont have to post.

Conditions are always used

a. only in if statement.

b. Usually in if and while statements.

c. Usually in if , while , and switch statements.

d. Only in switch statement.

Question 2

Given variable t representing temperature, write a condition where temperature falls either in the range of -12 to 32 degrees or in the range of 60 to 88 degrees.

Question 3

In a switch statement syntax, we have switch (x) where x is best described as

a. A condition.

b. A value.

c. An expression.

d. A statement.

Question 4

The grading policy is: 90 points or more, A; 80 to 89, B; 70 to 79, C; 60 to 69, D; 59 and below, F. To convert a point score to a letter grade, you should use

a. An if statement.

b. A switch statement.

c. A while statement.

d. A for statement.

Question 5
If you are to print a square of asterisks (*) and let the user tell you how big the square would be (number of asterisks in a row), you would use

a. A while loop.

b. A for loop.

c. A nested if statement.

d. Either a or b.

Question 6
You have a list of names and scores to enter into your program to fill the arrays. You don t know how long the list is, but would like the program to stop when the list reaches the end. Which of the following would you use?

a. A while loop.

b. A for loop.

c. A nested if statement.

d. Either a or b.

Question 7
In 6, how would you end the repetition?

Question 8

Given: function greeting (name) { alert( “Hi” + name + “!” ) } Write a line to call the function.

Question 9

Given: function greater (a, b)

{

if (a >= b)

return a

else

return b

}

Write a line to call the function.

Question 10
A function can return

a. 1 value

b. 2 values

c. As many values as it needs to.

d. No values.

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 13.2007 — Welcome to the Forum. We would be happy to help you, but only in case we have something to work on. Bring here some codes of your own bring your own answers to the questionnaire, even wrong, and will will come over with some assistance.

You see, we [I]do not [/I] someone else's homework or questionnaire. But we can help anyone to [I]complete[/I] or [I]correct[/I] their work, if [I]any[/I]...

You really should [I]learn[/I] Javascript basis if you want to be a web designer.
Copy linkTweet thisAlerts:
@Jake2authorMar 13.2007 — Conditions are always used

a. only in if statement.

b. Usually in if and while statements.

c. Usually in if , while , and switch statements.

d. Only in switch statement.

that for example i have NO idea what that means or where to find it, I have bought a book and read over the chapter many times...i enjoy attempting to reverse engineer code and learning that way, but going on a scavanger hunt isnt exactly exciting to me, nor the best way to use my time learning.

for example our first project was to:

Chapter 3 Project 1



Write a JavaScript program that obtains 3 numbers from the user, and then finds the largest and the smallest of the 3 numbers. Write the results to the page in complete sentences. (You need to use the if statement. Make sure to test your program using different combinations of 3 numbers.)





Discussions



  • 1. obtain 3 numbers from the user using the prompt() boxes, and store them in 3 variables such as a, b, and c.


  • 2. the next step is to compare the 3 variables to each other and determine which one is the largest and the smallest. In the process we assign the largest number to variable largest and the smallest number to variable smallest.


  • 3. Here is how:


  • var largest = a;

    if (largest < b)

    largest = b;

    if (largest < c)

    largest = c;

  • 4. Do the same to find the smallest. The only difference is to use variable smallest and to change the “<” to “>”.



  • my code turned out to be:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <title>Untitled Document</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    </head>

    <body>

    <script language="javascript" type="text/javascript">

    var a;

    var b;

    var c;

    a = prompt("Enter first number.","Number1");

    b = prompt("Enter second number.","Number2");

    c = prompt("Enter third number.","Number3");

    var largest = a;

    if (largest < b)

    largest = b;

    if (largest < c)

    largest = c;

    var smallest = a;

    if (smallest > b)

    smallest = b;

    if (smallest > c)

    smallest = c;

    document.write("The largest number is " + largest + " the smallest number is " + smallest + ".");

    </script>

    </body>

    </html>

    idk maybe javascript is my weak point most subjects come easy to me, but trying to find each one of those quiz answers is a project in itself it seems.
    Copy linkTweet thisAlerts:
    @KorMar 13.2007 — Conditions are always used

    a. only in if statement.

    b. Usually in if and while statements.

    c. Usually in if , while , and switch statements.

    d. Only in switch statement.

    that for example i have NO idea what that means or where to find it, I have bought a book and read over the chapter many times...i enjoy attempting to reverse engineer code and learning that way, but going on a scavanger hunt isnt exactly exciting to me, nor the best way to use my time learning.

    [/QUOTE]


    Yeap, you might be right to be confused, as the question is not quite well stated. [B][COLOR="Blue"]if[/COLOR][/B] and [B][COLOR="Blue"]switch[/COLOR][/B] are [I]statements[/I]. [B][COLOR="Blue"]while[/COLOR][/B] is a [I]loop[/I] (same as [B][COLOR="Blue"]for[/COLOR][/B]). On the other hand it is illogical to presume that something migh be used [I]always[/I] [COLOR="green"]and[/COLOR] [I]usually[/I] the same time (as that question says...)

    Anyway, if you would have seen those statements and loops, you would noticed that [I]all[/I] of them use conditions, thus the correct answer should be:

    c. Usually in if , while , and switch statements.
    Copy linkTweet thisAlerts:
    @KorMar 13.2007 — That homework is rather an academic one, as to find the extremes of a set of numbers, you may build an array with those numbers and sort them. But even so, you need a furthermore bitwise comparison between all the elements.

    So, you need a bitwise comparison. That means you need to check for all the 6 possible combination (3 elements taken by 2). You may use bitwise comparison with simple if...else statements, something like that:
    <i>
    </i>var largest, smallest;
    if(a&gt;b){
    if(a&gt;c){
    largest=a;
    if(b&gt;c){
    smallest=c
    }
    else{
    smallest=b
    }
    }
    else{
    largest=c;
    smallest=b;
    }
    }
    else{
    if(b&gt;c){
    largest=b;
    if(c&gt;a){
    smallest=a;
    }
    else{
    smallest=c;
    }
    }
    else{
    largest=c;
    smallest=a;
    }
    }
    Copy linkTweet thisAlerts:
    @Jake2authorMar 13.2007 — Yeah I dont know if it is right or not? but that is the code she said to use i dont want to overcomplicate or something and get it wrong if you know what i mean.

    however i am having some problems with the second project, the instructions are:

    Enhance Project 1 by checking the user input before trying to do the calculation. If the user enters a non-number for any of the 3 inputs, display a descriptive message using the alert() function and abort the program.



    Discussion:



    It is normally necessary to check the user input before using them for calculations. In our case, we want to make sure the user entries are numbers.



    We can use JavaScript function isNaN() to check to see whether a user’s entry is not a number. Here is how it looks like:



    var a = parseFloat(prompt("Enter number 1:", "number1"))

    if (isNaN(a))

    {

    alert("You should have entered a number ... bye.")

    }

    else

    {var b = parseFloat(prompt("Enter number 2:", "number2"))

    if (isNaN(b))

    . . . . . .


    When all 3 numbers are checked, we can then do the same as project 1 to find the largest and the smallest.

    my code so far is:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <title>Untitled Document</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    </head>

    <body>

    <script language="javascript" type="text/javascript">

    var a;

    var b;

    var c;

    var a = parseFloat(prompt("Enter number 1:", "number1"))

    if (isNaN(a))

    {

    alert("You should have entered a number ... bye.");

    }

    else

    {var b = parseFloat(prompt("Enter number 2:", "number2"))

    if (isNaN(b))

    {

    alert("You should have entered a number ... bye.");

    }

    else

    {var c = parseFloat(prompt("Enter number 3:", "number3"))

    if (isNaN(c))

    {

    alert("You should have entered a number ... bye.");

    }

    var largest = a;

    if (largest < b)

    largest = b;

    if (largest < c)

    largest = c;

    var smallest = a;

    if (smallest > b)

    smallest = b;

    if (smallest > c)

    smallest = c;

    document.write("The largest number is " + largest + " the smallest number is " + smallest + ".");

    </script>

    </body>

    </html>
    Copy linkTweet thisAlerts:
    @potterd64Mar 13.2007 — your code looks fine. Just a few things.

    var a;

    var b;

    var c;

    //Dont re-declare your variable below this point. Leave out the var.

    //This matters because later on for var b and c, when you declare them

    //they only exist in the scope of the if block, meaning they will go away

    //once this if block ends

    var a = parseFloat(prompt("Enter number 1:", "number1"))

    if (isNaN(a))

    {

    alert("You should have entered a number ... bye.");

    }

    else

    {var b = parseFloat(prompt("Enter number 2:", "number2"))

    if (isNaN(b))

    {

    alert("You should have entered a number ... bye.");

    }

    else

    {var c = parseFloat(prompt("Enter number 3:", "number3"))

    if (isNaN(c))

    {

    alert("You should have entered a number ... bye.");

    }

    //Make sure you add the right number of closing curly brackets here at

    //the end or else you'll get a syntax error. I think you need 3 more. Just

    //make sure there is one closing bracket for every opening bracket.

    also I'm not sure if its because of the auto formatting of the boards, but make sure you code in a way thats easy to read. example:

    [CODE]
    var a = parseFloat(prompt("Enter number 1:", "number1"))
    if (isNaN(a)){
    alert("You should have entered a number ... bye.");
    }else{
    b = parseFloat(prompt("Enter number 2:", "number2"))
    if (isNaN(b)){
    alert("You should have entered a number ... bye.");
    }else{
    c = parseFloat(prompt("Enter number 3:", "number3"))
    if (isNaN(c)){
    alert("You should have entered a number ... bye.");
    }
    }
    }
    [/CODE]


    This also helps to find how many closing brackets you need. Looks like I was wrong, you need 2 more brackets not 3
    Copy linkTweet thisAlerts:
    @Jake2authorMar 13.2007 — yeah i just finsihed right after you posted, the only thing that was messing me up was the closing brackets for the else statements, i was putting them after the var prompt, they didnt work anywhere else didnt think to put them at the end. so if for promt 1 i put in a non number I would get 3 alerts if that makes sense, thanks for the help =) I think im actually starting to learn something =D one question though, you said

    your code looks fine. Just a few things.

    var a;

    var b;

    var c;

    //Dont re-declare your variable below this point. Leave out the var.

    //This matters because later on for var b and c, when you declare them

    //they only exist in the scope of the if block, meaning they will go away

    //once this if block ends

    var a = parseFloat(prompt("Enter number 1:", "number1"))

    if (isNaN(a))

    { [/QUOTE]

    why is the
    [CODE]var a = parseFloat(prompt("Enter number 1:", "number1"))[/CODE]
    needed why couldent it just be
    [CODE]
    a = parseFloat(prompt("Enter number 1:", "number1"))[/CODE]

    it seems to work fine?



    my final code looks like
    [CODE]var a;
    var b;
    var c;
    var a;
    a = parseFloat(prompt("Enter number 1:", "number1"))
    if (isNaN(a))
    {
    alert("You should have entered a number ... bye.")
    }
    else
    {b = parseFloat(prompt("Enter number 2:", "number2"))
    if (isNaN(b))
    {
    alert("You should have entered a number ... bye.")
    }
    else
    {c = parseFloat(prompt("Enter number 3:", "number3"))
    if (isNaN(c))
    {
    alert("You should have entered a number ... bye.")
    }
    }
    }
    var largest = a;
    if (largest < b)
    largest = b;
    if (largest < c)
    largest = c;

    var smallest = a;
    if (smallest > b)
    smallest = b;
    if (smallest > c)
    smallest = c;

    if (isNaN(a))
    {
    document.write("You have entered a non numerical value, please try again using a number")
    }
    else if (isNaN(b))
    {
    document.write("You have entered a non numerical value, please try again using a number")
    }
    else if (isNaN(c))
    {
    document.write("You have entered a non numerical value, please try again using a number")
    }
    else{
    document.write("Of the 3 numbers " + a + ", " + b + ", and " + c + " the largest number is " + largest + " the smallest number is " + smallest + ".")
    }
    [/CODE]

    as you can see, compared to my last code, at the end i added some if and else ifs incase the input entered wasent a number so it would document write a different sentence..not sure if that is the most efficent way, but it seems to work =/
    Copy linkTweet thisAlerts:
    @potterd64Mar 14.2007 — why is the
    [CODE]
    var a = parseFloat(prompt("Enter number 1:", "number1"))[/CODE]


    needed why couldent it just be
    [CODE]
    a = parseFloat(prompt("Enter number 1:", "number1"))[/CODE]

    it seems to work fine?[/QUOTE]


    Right, that was just my mistake.

    Also to make the code look better at the end you could do this
    [CODE]if (isNaN(a) || isNaN(b) || isNaN(c)){
    document.write("You have entered a non numerical value, please try again using a number")
    }else{
    document.write("Of the 3 numbers " + a + ", " + b + ", and " + c + " the largest number is " + largest + " the smallest number is " + smallest + ".")
    }[/CODE]

    the || is an OR, meaning if anything separated by the ||'s turns out to be true then execute the if block.
    Copy linkTweet thisAlerts:
    @Jake2authorMar 14.2007 — ahh yeah thx...i just finished all 5 projects and my quiz i got 7/10 for the quiz above the class average of 59! =) hahah

    I do have one question though, how would I do this

    "Create a date variable representing the date of Christmas of year 2005." ?
    Copy linkTweet thisAlerts:
    @bogdachMar 14.2007 — What college are you from? I am from California Victor Valley College and I have got exactly same Quiz.
    Copy linkTweet thisAlerts:
    @Jake2authorMar 14.2007 — I dont speak russian, but I can use a translator haha, yeah I go to victor valley college in california

    Dont ii1 &#1075;&#1086;&#1074;&#1086;&#1088;&#1080;&#1090; &#1088;&#1091;&#1089;&#1089;&#1082;&#1086;&#1075;&#1086;, &#1085;&#1086; &#1103; &#1084;&#1086;&#1075;&#1091; &#1080;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1100; &#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1095;&#1080;&#1082;&#1072; haha, yeah &#1103; &#1080;&#1076;&#1091; &#1082; &#1082;&#1086;&#1083;&#1083;&#1077;&#1078;&#1091; &#1076;&#1086;&#1083;&#1080;&#1085;&#1099; victor &#1074; california
    Copy linkTweet thisAlerts:
    @bogdachMar 14.2007 — Do you need next Quiz?
    Copy linkTweet thisAlerts:
    @Jake2authorMar 14.2007 — idk how to PM you, whats your MSN, YIM, or AIM if you have it? so i can talk to you on instant messanger
    Copy linkTweet thisAlerts:
    @bogdachMar 14.2007 — I have YIM user name bogdach.
    Copy linkTweet thisAlerts:
    @KorMar 14.2007 — ahh yeah thx...i just finished all 5 projects and my quiz i got 7/10 for the quiz above the class average of 59! =) hahah

    I do have one question though, how would I do this

    "Create a date variable representing the date of Christmas of year 2005." ?[/QUOTE]

    http://www.w3schools.com/js/js_obj_date.asp
    ×

    Success!

    Help @Jake2 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 5.28,
    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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...