mercredi 28 juin 2017

Javascript IF loop not working properly

Just recently trying to get my head around javascript as I'm doing some front-end web development however I have just discovered something acting not quite as it should.

In the past, IF statements have worked exactly as they should, running the code if and only if the statement is true. However when I run this statement:

if ('2' !== 'None' && '2' !== '0') {
    alert('THIS IS A TEST')
}

Nothing happens. There are no syntax errors and I know the statement contained within the if loop evaluates to true as when I run it through the google console it tells me so.

Am I making a stupid mistake or I am I missing the intricacies of javascript logical operators.

Thanks to all who help me!

Can C# decide what variable to assign a value to? [duplicate]

This question already has an answer here:

Is there a way to write code so that when a user gives input, either a string or a number, that the program will choose the most appropriate of the available variables that have been declared?

Pseudocode example:

static void Main()
{
    int A;
    string B;

    Console.Write("enter something: ");

    if (user enters a number)
        A = int.Parse(Console.ReadLine());
    else
        B = Console.ReadLine();
}

JavaScript: only display div if both conditions apply

I am trying to only display a div with ID of tiitutormsg if it is the case that an element with ID inboxTable AND there are more than two tabs on the screen.

Unfortunately the code below means that the div will also be displayed on pages without inbox table but where the number of tabs is more than two :(

I tried nested if statements to get around this, but no luck.

 if (!document.getElementById('inboxTable') && countItems('nav-tabs') <= 2) {
    /* do nothing */
  } else {
         document.getElementById("tiitutormsg").style.display = 'block';
         document.getElementById('overlay').style.display='block';
  }

unable to retrieve POSIXct from numeric format after ifelse statement (R)

I have a table like so:

dtab<-data.table(Arr.Dep=c("A","D"),
       time=c("2017-05-01 04:50:00","2017-05-01 04:55:00"))

dtab[,time:=parse_date_time(dtab$time, c("%y-%m-%d %H:%M%S"))]

Operations on the date and time column seem successful:

dtab[,time2:=time+2]

But if I try to run an ifelse statement, the POSIXct format goes back to numeric and I seem to be unable to bring it back to date and time.

dtab[,time3:=ifelse(dtab[,Arr.Dep]=="A",dtab[,time]+2,"hello")]

I saw the issue has already been raised: R- date time variable loses format after ifelse

Unfortunately it's not of great help to me, as when I try to follow the example - adding 2 seconds rather than replacing with NA as in the OP -, I hit an error anyway. Any help?

Reduce CPU time of if-elif statements

I have an if-elif statement, which I believe not be very efficient:

number = 1000

switch = {
    '1': False,
    '2': False,
    '3': False,
    '4': False,
    '5': False,
    '6': False,
    '7': False,
    '8': False,
    '9': False
}

for i in range(number):
    for j in range(number):
        if some_condition:
            if i <= something and j <= something:
                switch['1'] = True
            elif i <= something and j <= something:
                switch['2'] = True
            elif something < i <= something and j <= something:
                switch['3'] = True
            elif something <= i < something and j < something:
                switch['4'] = True
            elif something <= i < something and something < j something:
                switch['5'] = True
            elif something <= i < something and something and j >= something:
                switch['6'] = True
            elif i >= something and j <= something:
                switch['7'] = True
            elif i >= something and something < j <= something:
                switch['8'] = True
            elif i >= something and  j >= something:
                switch['9'] = True

for i in switch:
    if(switch[i] == True):
        print(i)

As you can see, the statement looks pretty ugly. Since number is big, it takes almost 2 seconds for the execution.

Is there any way I could lower the CPU time?

I tried this answer, but my statement conditions are different.

Thank you.

If statement skips the elements except the first one in the for loop. How can I get the right solution fır the other elements?

for (int i = 0; i < dt.Rows.Count; i++)
 {

       if (textBox1.Text == dt.Rows[i]["FIRSTNAME"].ToString().ToLower() && textBox2.Text == dt.Rows[i]["LASTNAME"].ToString().ToLower())

       {
              Main ss = new Main(); // Main is the another form which is seen after the successful enterance.
              ss.Show();
               break;
        }

       else {
       MessageBox.Show("UserName or Password is Wrong");
         }
     }

*I want to create a Windows form application using C# and PL/SQL database. I have a data information which consists of the FİRSTNAME and LASTNAME of the two persons. Because of the for loop, I get both of the success and the failure messages at the same time for the second person's information. When for loop cannot match the second person's information with the first person's information, it shows the failure message. Then it sees right information. So, it returns the true message to me. *

**How can I return the beginning of the if statement to get the all solutions until the end of the database? I put the else statement's codes out of the for loop. I got always the failure message because of the non-existing the if statement to Control the failure.

Shortly, what do I need to do? **

I can't use If Statement inside Foreach Statement

Why the if statement inside foreach statement is not working? and my array_search function is also not working, im using yii framework

the if statement should print the brand Name but it prints false, may i know the scenario why the if statement returns me a null value or empty, thank you in advance

function getColumnKey($brand_name){
    $columnKey = '';

        $five_up_brands = array('K'=>"Coke",'L'=>"Sprite",'M'=>"Royal");
       array_search($brand_name, $five_up_brands);

       foreach ($five_up_brands as $k => $v) {

            if($v == $brand_name){

                $columnKey = $k;
            }
       }

    return $columnKey;
}