<button class="game-panel-item__copy" onClick="copyElement(${group.id})">
Copy
</button>
const copyElement = (elementId, elementObj) => {
if (elementObj){
const copiedElement = elementObj
}
else{
const copiedElement = selectedElements.filter(element => element.id === elementId)
}
let element;
element = {
...copiedElement[0],
id: generateElementId()
}
if (selectedElements === winds || selectedElements === areas) {
element.params = copiedElement[0].params
}
if (selectedElements === groups) {
copiedElement.elements.forEach((el)=>{
elements.elements.push(copyElement(el.id, el))
})
}
if (elementObj) {
if (elementObj.params) {
if ('forse' in el.params) {
winds.push(element)
} else if ('coup' in el.params) {
areas.push(element)
}
} else {
winds.push(element)
}
return element
} else {
selectedElements.push(element)
renderAll()
}
}
let example = 3;
if (example > 1) {
alert("Yes!"); // Yes! - работает.
}
if (condition) {
let example = 3;
}
if (example > 1) { // Uncaught ReferenceError: example is not defined
alert("Yes!");
}