我的 JavaScript 需要幫助,當用戶單擊按鈕時,我想提示用戶輸入分數(0-100),然后根據該分數回傳一個等級(例如 - 100-80=A,79-60=B ... <30 = F)順便說一下,請解釋每個步驟的完成方式和原因,因為我很愚蠢,謝謝。
<!DOCTYPE html>
<html>
<head>
<title>Marks to Grade Conversion</title>
<style>
h1 {font-family:serif; font-size:36px; color:#ff0000; text-align:center}
h2 {font-family:sans-serif; font-size:24px; color:#000000; text-align:center}
body {background-color:#FFCC00}
</style>
</head>
<body>
<h2>Faculty of Computer science</h2><br>
<h1>End of year module test results Mark to Grade utility</h1><br><br>
<h2>Click the button to enter the Mark and display the Grade</h2><br>
<h2><button style="font-size:24px; height:50px; width:300px"; onClick="ConvertMark()"> Click to enter the mark </button></h2><br>
<h1 id="display grade here"></h1></b></td>
uj5u.com熱心網友回復:
很基本。撰寫你的函式,獲取輸入,轉換,顯示結果
function ConvertMark(){
let display = document.getElementById('display')
let grade = prompt("Enter grade: ")
let alpha = "";
if (grade >= 90)alpha = 'A'
else if(grade >= 80)alpha = 'B'
else if(grade >= 70)alpha = 'C'
else if(grade >=60)alpha = 'D'
else alpha = 'F'
display.innerHTML = alpha
}
h1 {font-family:serif; font-size:36px; color:#ff0000; text-align:center}
h2 {font-family:sans-serif; font-size:24px; color:#000000; text-align:center}
body {background-color:#FFCC00}
<h2>Faculty of Computer science</h2><br>
<h1>End of year module test results Mark to Grade utility</h1><br><br>
<h2>Click the button to enter the Mark and display the Grade</h2><br>
<h2><button style="font-size:24px; height:50px; width:300px"; onClick="ConvertMark()"> Click to enter the mark </button></h2><br>
<h1 id="display"></h1>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405466.html
標籤:
上一篇:如何使內容顯示在三列而不是一列?
下一篇:去除多余的寬度
