Skip to content

Commit

Permalink
Complete Assignment1-3
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxoxo committed Jul 5, 2024
1 parent 9af4481 commit 1a73b24
Show file tree
Hide file tree
Showing 5 changed files with 1,177 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Week3/NodeJS/Public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.numberForm,
form {
display: flex;
flex-direction: column;
margin: 10px;
}
form {
justify-content: center;
align-items: center;
}
input,
button {
padding: 10px;
margin: 5px;
}
#result {
margin-top: 20px;
text-align: center;
}
43 changes: 43 additions & 0 deletions Week3/NodeJS/Public/sum.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<div class="numberForm">
<form id="numberForm">
<label method="post">Enter a positive integer</label>
<input type="text" />
<button type="submit">Submit</button>
</form>
<h1 id="result"><h1></h1>
</div>

</body>

<script>
const numberForm = document.getElementById("numberForm");

const result=document.getElementById("result")

numberForm.addEventListener("submit",(event)=>{
const numberValue = document.querySelector("input").value;
event.preventDefault()
if(numberValue === ''){
result.textContent='Lack of Parameter'
}else if(!Number.isInteger(Number(numberValue))|| numberValue<=0||isNaN(numberValue)){
result.textContent='Wrong Parameter'
}else{
fetch(`/getData?number=${numberValue}`)
.then(function(response){return response.text()})
.then(function(data){result.textContent = `${data}`})

}
}
);


</script>
</html>
Loading

0 comments on commit 1a73b24

Please sign in to comment.