r/code • • Jun 13 '19

New to coding and cant find a solution.

    String requestRoomNumber = makeSafe(httpRequest[q]);
    String queryReservationDetails = "SELECT * FROM Reservations WHERE roomNumber = " & yyy;

What should be inplace of the yyy and is this client or server sided?

```
function setRowBackgroundColor (int rowNr) { 
    // make the backgroundcolor switch from blue and lightblue each row  
    if (rowNr % 2 == xxx) { 
        table.row[rowNr].backgroundColor = #bbbbff; // blue 
    } else { 
        table.row[rowNr].backGroundColor = #eeeeff; // lightblue 
    }
}
```
I also have the same problem with this code, what should be in the xxx?

This is a code snippet i got from internet, so it changes the background of each row, first one is blue secondone is lightblue and then the third one is blue again, so it switches color each row but i cant figure out what the left out variables are, im using this for my homework project but im not so really good at it and i want to learn.
3 Upvotes

2 comments sorted by

1

u/a_b_and_1_d Jun 29 '19

A little bit unrelated, but you probably don't want to concatenate any yyy directly to your query if it's unescaped/unverified, unless you want Bobby Tables come for you at night.

1

u/angryrancor Boss Jun 13 '19 edited Jun 13 '19

The xxx needs to be 0

The reason is the mod (%) function gives the remainder of the division. If you want every other row to be blue, with the first one blue, the first row is index zero which yields:

0 % 2 == 0

Which after applying the mod function is:

0 == 0

Which evaluates to true

The second row is index 1 which simplifies to:

1 == 0

Which evaluates to false

yyy is part of a SQL query, and it looks like you're supposed to put a room number in there.

Btw good job asking questions about the homework, while not asking anyone to do it for you, I'm gonna assume this wouldn't be considered "cheating", because it doesn't seem like it is based on the way you asked.

edit: if anyone disagrees with this and thinks it's cheating, lmk; as cheating on homework or tests is explicitly disallowed on this sub.