I have a function that should display 4 different flags, but it's not working as expected. There are no error messages, but the flags are not being printed either. I've tried everything I could think of and now I'm stuck. Can someone please help me out?
(function () {
'use strict';
function draw() {
for (var i = 0; i < v.length; i++) flagTarget.init()
}
var flagTargetIvoryCoast = document.getElementById('flag-elfenbenskusten');
var flagTargetSweden = document.getElementById('flag-sverige');
var flagTargetMauritius = document.getElementById('flag-maruritius');
var flagTargetJapan = document.getElementById('flag-japan');
var flagTarget = {
init: function () {
if (flagTargetIvoryCoast) {
var flagIvoryCoast = '<div class="flag ivory-coast"><div class="part1"></div><div class="part2"></div></div>';
console.log('drawing flag Ivory Coast'),
flagTargetIvoryCoast.innerHTML = flagIvoryCoast;
}
if (flagTargetSweden) {
var flagSweden = '<div class="flag1 sweden"><div class="box1"></div><div class="box2"></div><div class="box3"></div><div class="box4"></div></div>';
console.log('drawing flag Sweden'),
flagTargetSweden.innerHTML = flagSweden;
}
if (flagTargetMauritius) {
var flagMauritius = '<div class="flag2 mauritius"><div class="box1"></div><div class="box2"></div><div class="box3"></div><div class="box4"></div><div class="box5"></div></div>';
console.log('drawing flag Mauritius'),
flagTargetMauritius.innerHTML = flagMauritius;
}
if (flagTargetJapan) {
var flagJapan = '<div class="flag3 japan"><div class="box1"></div><div class="cirkel1"></div></div>';
console.log('drawing flag Japan'),
flagTargetJapan.innerHTML = flagJapan;
}
}
},
flagTargetIvoryCoast = Object.create(flagTarget),
flagTargetSweden = Object.create(flagTarget),
flagTargetMauritius = Object.create(flagTarget),
flagTargetJapan = Object.create(flagTarget),
v = [
flagTargetIvoryCoast,
flagTargetSweden,
flagTargetMauritius,
flagTargetJapan,
];
draw(),
console.log('Sandbox is ready!')
}());
My console output shows the flags being drawn multiple times, and I can't figure out why. Any assistance would be greatly appreciated!