"What is her name?"
I. If followed by a particle or copula(-だ/です), -"なん" before consonant [t], [d], [n]. "なん-の" "なん-です-か" "なん-で" "なん-と" etc.
In this case, when we want to emphasize that we are asking "WHAT," it's ok to pronounce as "なに." -"なに" for all other cases. "なに-が" "なに-を" "なに-も" etc.
II. If followed by a counter(to ask "how many/much"), use "なん". "なん-にん" "なん-かい" "なん-だい" "なん-まい" etc. 「何人・何回・何台・何枚」
III. If followed by a noun(to ask "what ....."), use "なに." "なに-いろ(what color)" "なに-ご(what language)"「何色・何語」
IV. There are exceptions. "なん-ようび(what day of the week)" 「何曜日」
*The answer is not mine. Just found it on the Internet and thought to live it here.
The 'の' is part of 'Her'.
The particle supports the meaning of 'かのじょ'. 'かのじょ' alone can not be 'her'. 'Her' is not '彼女/かのじょ' but ’彼女/かのじょ together の’.
'I' is 'わたしは/わたしが' . 'My' is 'わたしの'.
'She' Is 'かのじょは/かのじょが'. 'Her' is 'かのじょの'.
(In here. because 'her' has other meaning)
This 'の' is resemble 'of' or 'apostrophe s'.
'her name' is 'かのじょのなまえ'.
'name of Tanaka' is 'たなかのなまえ'.
'Tanaka's name' is 'たなかのなまえ'
In this case, かのじょの名前 needs to be grouped together in this particular order because it means 'her name'. の is used here to show possession and functions like 'of' or apostrophe s in English. It's a bit easier to understand if you replace かのじょ with a noun, for example: 先生の名前 means 'teacher's name' or 'name of teacher'. If you flip around: 名前の先生 would mean 'name's teacher' or 'teacher of name' which doesn't make sense. Similarly, 名前のかのじょ ('name's she' or 'she of name') doesn't make sense so you can't just change the order however you like.
名前はかのじょの何ですか would translate into something like 'her what is name?'
Because this way you don't connect the name with the girl ("名前" could be the name of anyone). You don't make your listener/reader understand that the center (and subject) of your sentence is the name. Instead you shift the girl (かのじょ) at the center making her the subject, while the word "名前" has no clear function in the sentence
Constant usage of these 彼 and 彼女 by Duolingo is a bit annoying, since those pronouns are rarely used by Japanese people (except for some situations). And for me 彼女の名前は何ですか? sounds more like 'What is your girlfriend's name?' which would be the most typical usage of 彼女. I mean, what's wrong with ususal (and much more common) その人/あの人?