What is Nth in "Nth-child and "Nth-to-last"?

What is Nth in "Nth-child and "Nth-to-last"?
0.0 0

#1

Hello boys/girls,

I am following the freecodecamp.com course and came across this " $(“target:nth-child(2)”) " the first time i saw nth but there was no explanation about it. i was expecting more info later but that didn’t come. now i am at the Java script part of the course and Nth comes back but now in javascript, quote:“You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character.” here they talking about Nth-to-last but i still dont know what Nth stands for. google/search in freecodecamp ain’t giving me a answer.

anyone ?

tanks in advance!


#2

N is just a variable for some number. So nth-child(2) is the second child.


#3

N here is just any given number. If N was 2, Nth to last character in a string would be the second to last character. For ex In the string “Time is Money”, Nth to last would be “e” if N was 2 and it would be “M” if N was 5. Your JavaScript code has to probably compute either “Nth to Last” value in an Array or Nth Child for any value of N.

I am not sure which project in Freecodecamp this is and I have not reached there yet, but you can try to assume that N is a value provided by the User and your JavaScript function has to compute something using this value for N.


#4

oh ok so i have to read Nth-child(2) as 2th-child or " i am asking for the 2th child of this parent".
count “Nth” times then give me the name of the “object” on this spot.
an i see that Nth is only used in Nth-child() or Nth-to-last so Nth on its own is nothing right ?


#5

@Gualathar

Yes, nth-child is going to give you the nth child element of some parent.

I guess you coudl say N “on it’s own” doesnt have a defined value. It’s just a way of saying “some number” — a variable.


#6

Yes. It only makes sense with some context. For example, “Wirite a function nthLetter(n, string) that returns the nth letter in string.”


#7

I get it, thank you all for your assistance :smile: