Ask Experts Questions for FREE Help !
Ask
    mik4944's Avatar
    mik4944 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 12, 2010, 02:51 AM
    Javascript code to find whether number is positive or negative using switch statement
    We cannot use if statement it has o be done using switch only
    objectundefined's Avatar
    objectundefined Posts: 45, Reputation: 2
    Site Dev
     
    #2

    Oct 20, 2010, 04:53 PM
    When you write a "boolean statement" (i.e.: the contents of an "if" statement) outside of an "if" statement, it returns either true or false.

    Your boolean statement is as follows:
    Code:
    (num < 0)
    This can become the target of your switch like so:

    Code:
    switch(num < 0) {
    case true:
        alert('NUMBER IS NEGATIVE');
    break
    case false:
        alert('NUMBER IS POSITIVE OR ZERO');
    break
    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

How do I find the nth root of a number in code [ 2 Answers ]

In a mathematical formula how can I find the 5th root of a number (similar to the SRT(x) function

Positive and negative statement identification [ 3 Answers ]

How should I identify whether the attitude test statement related to teaching profession is + or _? e.g teaching leads to a luxurious life in likert sclale. Why do u think teachers develop negative attitudes in teaching?

Positive or negative externalities [ 1 Answers ]

Does the oil industry have positive or negative externalities and if so, what are they?

Is it positive or negative? [ 3 Answers ]

I took a pregnancy test yesterday. It was negative. Something told me to look at it again this morning and it had a very tainted yellow line next to the very bright pink line. I read in an article that a test is only correct up to 10 min otherwise it evaporates and the results may change. Let me...

Is it a positive or a negative? [ 4 Answers ]

Ok so I took a test today and the results said negative so I put it or the counter and walked away for a couple of hours when I came back it had a very light blue plus so does this mean a negative or a positive? I'm so confussed:confused: :confused: :confused: :confused:


View more questions Search