JavaScript Introducing JavaScript Finishing the Game Wrapping It Up

Angelic Sanoy
Angelic Sanoy
2,641 Points

I downloaded the Introducing Javascript project. When I open the index.html. Nothing works. Any idea?

I downloaded the Introducing Javascript project. When I open the index.html. Nothing works. Any idea?

2 Answers

So if you load up the page, and open up the console, you'll probably see an error similar to below:

Uncaught DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext': 
The image element contains cross-origin data, and may not be loaded.

There's an entire world of Cross Origin Resource Sharing (CORS) - but that's definitely out of score for this course!

To get the code up and running, the easiest way is to run it locally on your machine. This sounds like it would take a lot of effort, but can be done in a matter of seconds using python's SimpleHTTPServer.

To do this:

  • Launch a terminal window.
  • Switch to the directory containing the files you wish to run locally
    (e.g cd ~/Desktop/introducing_javascript/bonus_game)
  • Then run the following command:
    python -m SimpleHTTPServer 8000
  • Open up your browser and navigate to http://localhost:8000/ and the everything should be running!

Hope this helps!

Regards
Berian

Angelic Sanoy
Angelic Sanoy
2,641 Points

Yes. I just use a cdn to remove the error and warnings but it index.html is still not working. Should I revert back the phaser.js? What do you think is the best approach after running the code above?

How can I make sure this works in all audience if I upload this in a live site?

Btw, thank u so much!

Angelic Sanoy
Angelic Sanoy
2,641 Points

I just installed a python but it's still giving me this error? Any idea why? http://prntscr.com/m0arid

Ahh that's because Python hasn't been added the Windows PATH. I'm on Mac, so python kind of just works here.


If you've already installed Python 2.7 then you need to follow these instructions:

  1. Open System Properties (Right click Computer in the start menu, or use the keyboard shortcut Win+Pause)
  2. Click Advanced system settings in the sidebar.
  3. Click Environment Variables...
  4. Select PATH in the System variables section
  5. Click Edit
  6. Add Python's path to the end of the list (the paths are separated by semicolons). For example: C:\Windows;C:\Windows\System32;C:\Python27

If you have installed Python 3, the installation should have included an option to add python.exe to the system search path. The SimpleHTTPServer python command is slightly different on py3 however,
python -m http.server

Hope this helps!

Angelic Sanoy
Angelic Sanoy
2,641 Points

Thank you! Alternatively, I use VS but I will test this out shortly. :) Really appreciate it.