chapter 6 class 10 Java Script image

    SEBA 
    CLASS- 10
    CHAPTER-6
    Introduction to JavaScript

    OBJECTIVES TYPE QUESTIONS


    1. Fill in the Blanks:

    a. The alert box is used to displays information to the user.

    b. A variable is a storage area where value is stored and retrieve when required.

    c. The modulus operator finds out the remainder.

    d. The ! (exclamation mark) operator is a unary operator.

    e. The conditional operator uses ? (question mark) and : (colon) characters.

    2. Write TRUE or FALSE.

    a. The semi colon at the end of simple statement in Java Script is mandatory. FALSE

    b. In Java Script MARKS and marks are treated as the same variable. FALSE

    c. A simple statement must be enclosed in braces. TRUE

    d. A compound statement consist of several instructions grouped in a block. TRUE

    e. The switch statement can only be used to compare an expression against constant. TRUE

    3. Multiple Choice Questions:

    a. Which one is a valid name in JavaScript.

    1employeename

    b. A block of statement is enclosed within.

    { } ( curly Braces)

    c. The statement used to exit from the switch…. case statement is

    exit

    d. ___ takes a number as input from the user.

    Prompt dialog box

    e. Which one of these is not an arithmetic operator in JavaScript.

    / (backward Slash)

    f. ==is a/an

    Relational Operator.


    Click To Top

    DESCRIPTIVE TYPE QUESTIONS

    1. Short answer questions:

    a. What are the three data types in JavaScript?

    The three data type in JavaScript are:

    i. Number Eg: 56, 45.12 etc.

    ii. String Eg: “Grade” etc

    iii. Boolean Eg: True or False.

    b. How will you declare variables sub1, sub2, and sub3 in JavaScript?

    We can declare variables sub1, sub2 and sub3 in JavaScript as:

    var sub1, sub2, sub3;

    c. Name the different form of if statement.

    The different form of if statement is:

    i. if statement

    ii. if… else statement

    iii. if… else if statement 

    d. Name the three logical operators.

    The three logical operators are:

    i. && (AND) operator

    ii. ||(OR) operator

    iii. ! (NOT) operator

    e. Write the statement equivalent to A++ and A--.

    The statements equivalent to A++ and A- - are:

    i. Increment Operator

    ii. Decrement Operator 

    f. Write the short hand form for the following.

    A = A + 15

    B = B + 1

    A+=15

    B+=1

     

    2. Long answer question:

     

    a. Explain the two types of comments in JavaScript.

    Comment mean not executable statement or ignore statement.

    The two types of comments in JavaScript are:

    i) Single line comment: A comment which is restricted to only a single line. It always starts with a pair of (//) backward slash. The browser ignores anything typed from the pair of slash (//) till the end of the same line. Example: // single line comment.

    ii) Multi line comment: A comment which is applicable to one or more statements. It always indicates with a (/*) backward slash asterisk and (*/) asterisk backward slash. The browser ignores the statements between these characters. It is also known as a block comment: Example: /*This is block comment known as multi line comment */.

     

    b. What are the rules for naming the JavaScript variables?

    The rules for naming the JavaScript variables are given below:

    i) In JavaScript a variable may include only letter A to Z, a to z, 0 to 9, the dollar symbol $, and the _ underscore.

    ii) No other characters such as a space, or punctuation are allowed in a variable name.

    iii) The first character of variable name can be only a to z, A to Z and _ underscore ( no number)

    iv) Name are case sensitive

    v) There is no set limit on variable names length.

    vi) You must declare the JavaScript variable with the var keyword.

     

    c. What are the limitation of the switch statement?

    The limitations of a switch statement are:

    i) The case label cannot be a variable. Example: case n: where n is a variable.

    ii) the case label cannot be a range. Example: case (1.3):. This is not a valid content.

     

    d. What is the different between simple and compound statements?

    The differences between simple and compound statement is that:

    A simple statement consists of a single instruction ending with a semi colon (;). It does not required braces to enclosed it. Whereas,

    A compound statement consists of several instructions grouped in a block. It must be enclosed in braces if we wish to treat them all as a single statement.

     

    e. Explain the working of conditional operators with an example.

     The conditional (ternary) operator is the only JavaScript operator that takes three operands.

     A condition followed by a question mark (?), then an expression to execute if the condition is true followed by a colon (:), and finally the expression to execute if the condition is false. This operator is frequently used as a shortcut for the if statement.

    Example: Below is the code finding the age below 18 or above 18 years using the conditional operators.

    <!DOCTYPE html>

    <html>

    <head> </head>

    <body>

    <script>

    var age, result;

    age = 20

    result = age > 18 ? You are over 18 year : You are below or equal to 18 years

    document.write (result)

    </script>

    </body>

    </html>


    Click To Top


    APPLCATION BASED QUESTIONS:


    1. Jasmin has written the given code to display a message box on the screen, but the message box is not showing on the screen. Find the problem in this code and rewrite it to display the given statement in a message box.


    alert syntax code
     Answer

    <!DOCTYPE html>

    <html>

    <body>

    <script language = javascript type = text/javascript>

    alert(This is my first JavaScript Code)

    </script>

    </body>

    </html>

     


    2. Rewrite the following code using if…..else if statement.

    switch  (direction)

    {

    case N : a = north ; break;

    case E : a = north ; break;

    case W : a = north ; break;

    case S : a = north ; break;

    default : a = Enter correct code;

    }

    document.write (a)

     Answer

     

    if (direction = = N)

    a= North

    else if (direction = = E)

    a= East

    else if (direction = = W)

    a= West

    else if (direction = = S)

    a= South

    else

    a = Enter correct code

     

    3. What will be the output of the following code:

    var a, b

    a= 5

    b = 10

    b+=a

    a++

    b- -

    document.write(a = + a + <br/>)

    document.write(b = + b )

      Answer

    Given, a= 5

                b = 10

    to find the var a, b= ?

    Given, b+=a

    Therefore,

     b = b+ a (According to Compound assignment operator+=  it adds the right-side operand to the left side and assign the result to the left side operand.)

    So, we got,

    b = 10 + 5 = 15 ( now the value in b = 15)

    Again, given

    a++

    Therefore,

    a = a + 1 (According to increment operator ++ it increases the value stored in a variable by one.)

    So, we got

    a = a+1 = 6 (now the value in a = 6)

    Lastly Given

    b- -

    Therefore

    b = b - 1 (According to decrement operator - - it decreases the value stored in a variable by one.)

    So, we got

    b = 15 – 1 = 14 (now the value in b = 14)

    So, we get the output

    a = 6

    b = 14


    4. Evaluate the following expression and find out its output, assuming b = 4 and c = 4

    a = b * 3 / 4 + c / 4 + 8 – b + 5 / 8

     Answer

    Solution

    a = b * 3 / 4 + c / 4 + 8 b + 5 / 8

    Now putting the value of b and c we get

    a = b * 3/4 + c/4 + 8 b + 5/8

       = 4 * 3/4 + 4/4 + 8 4 + 5/8

       = 12/4 + 4/4 + 8 4 + 5/8

       = 3 + 1 + 8 4 + 0.625

       = 12.625-4

       = 8.625

    Note: Solve every Mathematical Question using Arithmetic Operator Procedure.

     

    5. Assuming A = 5 and B = 6, what will be the result of the following statements:

    i. ((A != B) && (A >=B))

    ii. ((A != B) || (A <= B))

    iii) ! (A > B)

     Answer

    i. false

    Explanation:

    Given,

    (A != B) and then putting the values of A and B, we get,

    (5 != 6), means 5 is not equal to 6 , which is true.

    Again,

    (A >= B) and then putting the values of A and B, we get,

    (5 >= 6), means 5 is greater than or equal to 6, which is false.

    And,

    ((A != B) && (A >=B)), Contains logical operator && (AND). So According to && (AND) logical operator, if the both conditions (A != B), (A >= B) is true then only the result will be true, otherwise false.

    So, the final result in this case will be false.

     

    ii. true

    Explanation:

    Given,

    (A != B) and then putting the values of A and B, we get,

    (5 != 6), means 5 is not equal to 6 , which is true.

    Again,

    (A <= B) and then putting the values of A and B, we get,

    (5 <= 6), means 5 is less than or equal to 6, which is true.

    And,

    ((A != B) || (A <=B)), Contains logical operator || (OR). So According to || (OR) logical operator, if the both conditions (A != B), (A >= B) is false then only the result will be false, otherwise true.

    So, the final result in this case will be true.

     

    iii. true

    Explanation:

    Given,

    (A > B) and then putting the values of A and B, we get,

    (5 > 6), means 5 is greater than 6, which is false.

    And,

    !(A > B) Contains logical operator ! (NOT). So According to ! (NOT) logical operator, if the conditions (A > B) is true the result will be false, and if the condition is false the result will be true, in vice versa.

    So, the final result in this case will be true for the condition is false.

     

    6. Write the following if…. else statement using the conditional operator:

    if (x = = 100)

    a = “x is 100”

    else

    a  = “x is not 100”

     Answer

    a = x == 100 ? x is 100 : x is not 100(answer)

    Explanation:

    Since the general format of if… else statement for the given statement is:

    if (x ==100)

    {

    document.write(“x is 100”)

    }

    else

    {

    document.write(“x is not 100”)

    }

    So, relating this format with the question we get, condition = (x==100). We need to write the using conditional operator. So, the general format of conditional format is given below:

     

    var x = 100;

    x = x == 100? "x is 100": "x is not 100"

    document.write( x);

    The out put we get here is x is 100 as it has executed the true part, for in x the value is assign 100 and the condition we gave is x= x==100. so the final result we got using conditional operator a = x == 100 ? “x is 100” : “x is not 100” is x is 100.

     

     

     


    Click To Content