Answer:
Japan attacked Pearl Harbor to eliminate the US Naval fleet in the Pacific, at the time of the attack the US Carriers were not in port (Japan wanted to destroy the Carriers to stop any US effort to bomb Japan). If the Carriers were docked things could have been different.
A radar station in Hawaii spotted the japanese bombers, American officers thought it was a squadron of US fighters who were scheduled to come in.