Skip to content

Commit

Permalink
invalid error added
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaikTipu committed Apr 23, 2024
1 parent 78aa7c8 commit 41173bf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
33 changes: 25 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,44 @@ wu.addEventListener('click' , (event) => {
submit.addEventListener('click',(event) => {
event.preventDefault();
calAns();
})
function calAns (){
let final = parseInt(final_input.value);
let initial = parseInt(initial_input.value);
});


function calAns (){

let final = parseInt(final_input.value);
let initial = parseInt(initial_input.value);
let errortag = document.querySelector('.error');

errortag.innerText = '';
errortag.style.backgroundColor = 'inherit';

if(final < 1 || initial < 1 || !(Number.isInteger(final)) || !(Number.isInteger(initial)) ){
errortag.innerText = 'Invalid Values Entered';
errortag.style.backgroundColor = 'red';
setTimeout(() => {
errortag.style.backgroundColor = 'rgb(210, 128, 145)';
}, 300)

return;
}

if (eu.value == 'J') {

ans_e = (-2.18) * (Math.pow(final , -2 ) - Math.pow(initial , -2 )) ;
ans_e = ( (2.18) * (Math.pow(final , -2 ) - Math.pow(initial , -2 )) ) ;
energy_result.innerText = ans_e.toFixed(3) ;
} else if (eu.value == 'eV') {
ans_e = (13.6) * ((1/final)*(1/final) - (1/initial)*(1/initial)) ;
ans_e = ( (2.18) * (Math.pow(final , -2 ) - Math.pow(initial , -2 )) * (6.2415) );
energy_result.innerText = ans_e.toFixed(3) ;
}

if (wu.value == 'nm') {
ans_w_unit_nm = true ;
ans_w = (100/1.097) * (Math.pow(final , -2 ) - Math.pow(initial , -2 ));
ans_w = (100/1.097) / (Math.pow(final , -2 ) - Math.pow(initial , -2 ));
wavelength_result.innerText = ans_w.toFixed(3);
} else if (wu.value == 'm') {
ans_w_unit_nm = false ;
ans_w = (1/1.097) * (Math.pow(final , -2 ) - Math.pow(initial , -2 ));
ans_w = (1/1.097) / (Math.pow(final , -2 ) - Math.pow(initial , -2 ));
wavelength_result.innerText = ans_w.toFixed(5);
}

Expand Down
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<form action="#">
<label for="final">
<p>final state</p>
<input type="number" id="final" min="1" >
<input type="number" id="final" min="1">
</label>
<label for="final">
<p>initial state</p>
Expand Down Expand Up @@ -44,12 +44,13 @@

</form>
</div>
<div class="error"> </div>
</div>
<div class="range er">
<div class="wavebar bar">Wave Properties</div>
<img src="wave-properties.png" alt="Wave Properties" id="wave-properties_img"style="">
<div class="region_color" id="region" ></div>
<div class="region_color" id="color"></div>
<!--edited-->
</div>
<script src="app.js"></script>
</body>
Expand Down
17 changes: 16 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ body{
height: 75%;
width: 75%;
align-self: center;
margin-top: 2cm;
margin-top: 1cm;
display: flex;
flex-direction:column;
flex-wrap: wrap;
Expand Down Expand Up @@ -158,3 +158,18 @@ margin-left: 10px;
font-weight: bolder;

}
.error{
margin: 2px;
align-self: center;
width: 50%;
height: 1cm;
color: black;
text-align: center;
line-height: 2rem;
font-size: large;
font-weight: bold;
/* background-color: rgb(210, 128, 145); */
}
.errorRed {
background-color:red ;
}

0 comments on commit 41173bf

Please sign in to comment.