Simulador de JavaScript
⬅ Voltar
Aula Prática: JavaScript
// ======================= // VARIÁVEIS // ======================= let nome = "Aluno"; let idade = 20; // ======================= // SAÍDA // ======================= document.write("<h2>Olá, " + nome + "!</h2>"); document.write("Você tem " + idade + " anos.<br>"); // ======================= // OPERADORES ARITMÉTICOS // ======================= let a = 12; let b = 3; document.write("<h3>Aritméticos:</h3>"); document.write("Soma: " + (a + b) + "<br>"); document.write("Subtração: " + (a - b) + "<br>"); document.write("Multiplicação: " + (a * b) + "<br>"); document.write("Divisão: " + (a / b) + "<br>"); document.write("Resto (%): " + (a % b) + "<br>"); // ======================= // CONDICIONAL // ======================= document.write("<h3>Condição:</h3>"); if(idade >= 18){ document.write("Maior de idade<br>"); }else{ document.write("Menor de idade<br>"); } // ======================= // LAÇO // ======================= document.write("<h3>Contagem:</h3>"); for(let i = 1; i <= 5; i++){ document.write("Número: " + i + "<br>"); } // ======================= // ARRAY // ======================= let frutas = ["Maçã", "Banana", "Laranja"]; document.write("<h3>Frutas:</h3>"); frutas.forEach(fruta => { document.write(fruta + "<br>"); }); // ======================= // FUNÇÃO // ======================= function soma(a, b){ return a + b; } document.write("<h3>Soma:</h3>"); document.write(soma(5,3)); // ======================= // OPERADOR TERNÁRIO // ======================= document.write("<h3>Ternário:</h3>"); let status = (idade >= 18) ? "Adulto" : "Menor"; document.write(status);
Executar