2
1
To dynamically include a JavaScript file in a web page, you'd normally insert a <script>
tag pointing to your script. For example:
var js_file= document.createElement("script");
js_file.src='http://example.com/js.js';
document.body.appendChild(js_file);
Write JavaScript code will load an external JavaScript file in the current page and:
- Shortest valid answer wins
- The file is hosted on
https://pastebin.com/raw/rV6dDDj9
(content isconsole.log('Good job!');
) - The code must be vanilla JavaScript (no jQuery, etc.)
- Answer validity test is done in the web browser console. Criteria:
- URL requested and JS file downloaded.
- Console prints
Good job!
3
Welcome to PPCG! Unfortunately, I think this challenge has some problems. Are URL shorteners allowed? Do you expect any possible improvement beyond that? I don't know enough about javascript to be sure, but it looks fairly cut-and-dry. Just so you know, we have a Sandbox where you can post to receive feedback on your challenge before posting to the main site.
– FryAmTheEggman – 2016-05-24T21:04:33.987quite broad.... – Bald Bantha – 2016-05-24T21:08:24.833
1@FryAmTheEggman Thanks. I originally thought shortners wouldn't be allowed because I specified the exact URL, but I guess it's not an issue since people are using them. @ Bald You're welcome to give specific suggestions on the broad areas so I can try to limit the scope – Adi – 2016-05-24T22:00:34.247
@FryAmTheEggman This question is pretty trivial... – ericw31415 – 2016-05-25T06:51:26.910
Can we assume the page is using jQuery? One answer is assuming so, but I think this is a loophole.
– user48538 – 2016-05-25T10:37:19.2631I still think this isn't a good question. Currently I'm winning, because I could register a very short domain. – Bálint – 2016-05-25T10:50:59.530
@Bálint You're not winning because your answer isn't valid according to the criteria mentioned in the question. Check my comment under your answer. Also, numerous answers on this site include short domains and shortened URLs, so it seems to be an accepted practice. – Adi – 2016-05-25T10:54:51.763
Could you please clarify if the jQuery answer is valid? The poster seems to interpret the current page as this page, which differs from my interpretation. – Dennis – 2016-05-25T16:57:53.497
@Dennis I think your interpretation was indeed my original intention. I included that explicitly now. I hadn't anticipated that code-golfing involves using semantic loopholes in the wording of the question. I guess my next question would definitely be better. – Adi – 2016-05-25T18:43:16.020
You accepted the answer so early!?! You should have given it at least 4 or 5 days or a whole week! – Arjun – 2016-05-26T00:06:24.097
Downvoting because the challenge requires the use of sketchy link shorteners. – 12Me21 – 2018-05-21T19:31:33.027