The Battle of Midway happened after the attack on Pearl Harbor, at this time the Japanese navy in the pacific were superior to the U.S. pacific navy, but there was two instances that the U.S. humiliated Japanese, and that was a deciding factor in attacking midway.
The Japanese also wanted to take over Midway island to have a staging platform to invade Hawaii, and also they hoped to force U.S. to negotiate end war agreements in favor of Japanese terms.