Xem video hướng dẫn hiển thị đầu ra tại: https://drive.google.com/file/d/1KHPtny5l32VlCSHnyOiKm3Sm-6UZJ_so/view
Mục tiêu
Luyện tập hiển thị các thông báo dưới nhiều cách khác nhau
Mô tả- Hiển thị đầu ra
Trong phần này, chúng ta sẽ luyện tập các cách khác nhau để quan sát kết quả khi thực thi mã JavaScript.
Hướng dẫn
Bài tập 1: Hiển thị kết quả sử dụng hàm alert():
<button type="button" onclick="showMessage();">Click Me!</button>
<script>
function showMessage(){
alert('Xin chào!');
}
</script>
Bài tập 2: Hiển thị kết quả sử dụng thẻ HTML:
<div id="messageDiv"></div>
<button type="button" onclick="showMessage();">Click Me!</button>
<script>
function showMessage(){
document.getElementById('messageDiv').innerHTML = 'Xin chào!';
}
</script>
Bài tập 3: Hiển thị kết quả sử dụng hàm document.write():
<button type="button" onclick="showMessage();">Click Me!</button>
<script>
function showMessage(){
document.write('Xin chào!');
}
</script>
Bài tập 4: Hiển thị kết quả sử dụng hàm console.log():
<button type="button" onclick="showMessage();">Click Me!</button>
<script>
function showMessage(){
console.log('Xin chào!');
}
</script>
Lưu ý: Bật màn hình console của trình duyệt để có thể xem được kết quả hiển thị.
Để hoàn thành bài thực hành, bạn cần:
- Đưa mã nguồn lên GitHub
- Dán link của repository lên phần nộp bài trên CodeGymX
Xem thêm: Học Coding Bootcamp tại Việt Nam ở đâu để đi định cư tại Mỹ



0 Lời bình