That's entirely wrong. G is not "confused with" J or Y. Old English G had two pronunciations—a front of mouth G which became first a fricative and was then merged with the similar-sounding approximant which then had no representation in the
Roman alphabet (now normally spelled j in other Germanic languages, but y in English), and a back of mouth g which would later become the stop of Ghost. The front of mouth G would later be replaced by Y at the front of words, after Y lost its original value as a front-of-mouth u. At the end of words the back of mouth g became an aspirate, frequently written h, but often restored back to g to match the spelling of the noun declensions and verb inflections where it was not final. Final gh is then pronounced either f or (h) depending on the preceding vowels. Eventually a compromise was made with the spelling gh. Front g when preceding t would also be spelled gh. Front g when final would become i and be spelled so, and to avoid being mistaken for a mere flourish, final i would later be written as y (e.g. daily, when the i is central, but day when final). Words such as "joke" are spelled with J because they are from romance languages in which the Latin I became J, pronounced dʒ or ʒ.