Unable to get data from json and api on the browser

hi guys, this is my example code that i created for practicing fetching data from various source (from local text file, from local json file, from an API)
When i clicking get Text it is giving me my text file content in the body but when i am clicking get Json and get API data , it is giving me the code i have written in my js to get these things on the browser.
I’m guessing that i am making a coding error while coding this stuff. How can i get only data from these sources without that code.
since I don’t know how to add local text file and a json file, please add some local files from your systems to see what i am saying.


The Fetch API provides an interface for
fetching resources (including across the network).
It will seem familiar to anyone who has used XMLHttpRequest,
but the new API provides a more powerful and flexible feature set.


    "name": "John",
    "email": "john@example.com"
    "name": "Jane",
    "email": "jane@example.com"