What task am I attempting to accomplish?
I am trying to run two functions sequentially in JavaScript, but it seems that both functions are being called and executed simultaneously.
What seems to be the issue?
The setModalBox
function throws an undefined error when called before the setProjects
function.
What have I already attempted as a solution?
I have tried using Promise
with setTimeout
, which works sometimes. However, there are still instances where the setModalBox
function is called first and causes the same error.
Snippet of JavaScript code:
class Portfolio{
init() {
this.setProjects();
}
// Rest of the JavaScript code...
}
// HTML code...
HTML:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Projetos - Vitor Hugo's Portifolio</title>
<link rel="stylesheet" href="style.css" />
<script src="script.js" defer></script>
</head>
<body>
<header>
<div id="wrapperJS" style="position: relative; overflow: hidden">
<nav>
<a class="logo" href="/">Vitor Hugo</a>
<div class="mobile-menu">
<div class="line-1"></div>
<div class="line-2"></div>
<div class="line-3"></div>
</div>
<ul class="nav-list">
<li><a href="index.html">Home</a></li>
<li><a href="sobre.html">Sobre</a></li>
<li><a href="projetos.html">Projetos</a></li>
<li><a href="contatos.html">Contato</a></li>
</ul>
</nav>
</div>
</header>
<!-- Other sections of HTML... -->
</body>
</html>
I need guidance on how to resolve this issue. If more information is required, please let me know. My apologies for any spelling or grammar errors, as I am currently learning English.