Both are correct. In US English, people will often say ' I slept 8 hours', whereas in UK English, we say 'I slept for 8 hours.' There are a number of similar expressions where the two countries use slightly different expressions. Americans say ' I'll see you Friday.' We say ' I'll see you on Friday.' Americans say ' We work Monday through Friday.' We say 'We work from Monday to Friday.' They are not important differences, but they probably confuse learners. It's best if you can learn just UK English or US English, but if you are learning informally that's going to be difficult!