const API_BASE_URL = '';
const fetch = url => Promise.resolve([
'message1',
'message2',
'<button onclick="javascript:alert(\'boom!\');">X</button>'
]);
const list = [1, 2, 3, 4, 5];
// could be const
// "oddList" (or similar) would be a better name
let filtered = [];
// the whole loop could be replaced by a list.filter()
for (let i = 0; i < list.length; i += 1) {
// unnecessary double equal
if (list[i] % 2 == 1) {
filtered.push(list[i]);
}
}
// what if it's missing?
const messagesDiv = document.getElementById('messages');
fetch(API_BASE_URL + '/messages')
.then(messages => {
messages.forEach(message => {
// we could use some temlating language instead of creating elements by hand
const div = document.createElement('div');
// message should be sanitized
// should be "innerHTML"
div.innerHtml = message;
messagesDiv.appendChild(div);
});
});
// missing catch
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.