Code segment won't translate to JS