Take another look at the sentence:
At the hour Javier was supposed to be in trigonometry, he was instead flirting with pretty girls in the cafeteria needless to say, he was inadequately prepared to make the 98 that he needed on the final exam to pass the course.
Needless to say is an introductory transition. It begins the second main clause, he was inadequately prepared to make the 98. Generally, you need a comma to connect an introductory transition to the main clause that follows.