-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.html
75 lines (72 loc) · 2.48 KB
/
js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Live Code Editor</title>
<!-- Bootstrap CSS -->
<link
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
rel="stylesheet"
/>
<style>
/* CSS khusus untuk layout */
.code-editor {
width: 100%;
height: 200px;
font-family: monospace;
font-size: 14px;
}
.output-area {
border: 1px solid #ccc;
min-height: 200px;
padding: 10px;
margin-top: 10px;
background-color: #f8f9fa;
}
</style>
</head>
<body>
<div class="container mt-5">
<h2 class="text-center">JavaScript Live Code Editor</h2>
<div class="row mt-4">
<!-- HTML Editor -->
<div class="col-md-4">
<h5>HTML</h5>
<textarea id="html-code" class="code-editor form-control" placeholder="Write HTML code here"></textarea>
</div>
<!-- CSS Editor -->
<div class="col-md-4">
<h5>CSS</h5>
<textarea id="css-code" class="code-editor form-control" placeholder="Write CSS code here"></textarea>
</div>
<!-- JavaScript Editor -->
<div class="col-md-4">
<h5>JavaScript</h5>
<textarea id="js-code" class="code-editor form-control" placeholder="Write JavaScript code here"></textarea>
</div>
</div>
<!-- Button to Run the Code -->
<div class="text-center mt-4">
<button class="btn btn-primary" onclick="runCode()">Run Code</button>
</div>
<!-- Output Area -->
<div class="output-area mt-4" id="output-area"></div>
</div>
<!-- JavaScript -->
<script>
// Fungsi untuk menjalankan kode yang dimasukkan oleh pengguna
function runCode() {
// Mengambil nilai dari textarea HTML, CSS, dan JavaScript
const htmlCode = document.getElementById("html-code").value;
const cssCode = "<style>" + document.getElementById("css-code").value + "</style>";
const jsCode = "<script>" + document.getElementById("js-code").value + "<\/script>";
// Menggabungkan kode HTML, CSS, dan JavaScript
const fullCode = htmlCode + cssCode + jsCode;
// Menampilkan hasil di output-area
const outputArea = document.getElementById("output-area");
outputArea.innerHTML = fullCode;
}
</script>
</body>
</html>