Javascript - Tìm số lớn nhất trong 2 số

Tìm số lớn nhất trong 2 số

Ví dụ:

JavaScript: Accept two integers and display the larger

Mã nguồn:

<!DOCTYPE html> 
<html>
<head>
<meta charset=utf-8 />
<title>Write a JavaScript program that accept two integers and display the larger</title>
<script>
var num1, num2;
num1 = window.prompt("Input the First integer", "0");
num2 = window.prompt("Input the second integer", "0");
                                                 
if(parseInt(num1, 10) > parseInt(num2, 10)) 
  { 
  document.write("The larger of "+ num1+ " and "+ num2+ " is "+ num1+ ".");
  }   
else
  if(parseInt(num2, 10) > parseInt(num1, 10)) 
  {
  document.write("The larger of "+ num1+" and "+ num2+ " is "+ num2+ ".");
  }                  
else
  {
   document.write("The values "+ num1+ " and "+num2+ " are equal.");
  }
  
</script>
</head>
<body>
  
</body>
</html>

Xem ví dụ

Lưu đồ thuật toán:

Flowchart: JavaScript:- Accept two integers and display the larger

 



Chatbot Tư vấn Lộ trình CNTT 🤖
Chào bạn! Tôi có thể tư vấn về các lộ trình học CNTT dựa trên roadmap.w3typing.com. Hãy chọn một từ khóa dưới đây hoặc gõ câu hỏi của bạn (ví dụ: "Frontend", "Backend", "Python", "DevOps").