So... why does this code compile and run but the
length
function only produces zero no matter what string is input?
... about programming, growing up in the 1970's and 80's, games, science fiction, working in a charity book shop, films, spending too much time watching television, living in Basildon and Essex, and whatever else emerges from my fevered imagination. If you're reading this, it's your fault you clicked on the link: I am not responsible for your actions.
length
function only produces zero no matter what string is input?
The for loop doesn't have a semi-colon at the end. This means that the return is executed on the first iteration of the for (and terminating both the form and the function), no matter what the length of the string. The variable index is equal to zero at this point so the function will always return zero.
ReplyDeleteYou've jinxed me now!!!
ReplyDeleteIt'll be a walk in the park. I'd wear your nicest brown trousers, though.
Delete