<div class="container">
<div class="row">
<div class="col-sm-12">
<label>Digite a nota da primeira avaliação</label>
<input type="text" id="av-um">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<label>Digite a nota da segunda avaliação</label>
<input type="text" id="av-dois">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<label>Digite a nota da avaliação de recuperação</label>
<input type="text" id="av-rec">
</div>
</div>
<hr/>
<div class="row">
<div class="col-sm-12">
<button id="calc-media" class="btn btn-primary">Calcular Nota Média</button>
</div>
</div>
</div>
JavaScript
var a = 0;
var b = 0;
var c = 0;
var media = 0;
var primeiroMaior = {};
var segundoMaior = {};
document.getElementById("calc-media").addEventListener("click", function() {
// Pegando as notas das 3 avaliações
a = document.getElementById("av-um").value;
b = document.getElementById("av-dois").value;
c = document.getElementById("av-rec").value;
// / Verificando maior nota das três
if (parseFloat(a) >= parseFloat(b) && parseFloat(a) >= parseFloat(c)) {
primeiroMaior = {
'indice' : 'a',
'a' : parseFloat(a)
};
}
if (parseFloat(b) >= parseFloat(a) && parseFloat(b) >= parseFloat(c)) {
primeiroMaior = {
'indice' : 'b',
'b' : parseFloat(b)
};
}
if (parseFloat(c) >= parseFloat(a) && parseFloat(c) >= parseFloat(b)) {
primeiroMaior = {
'indice' : 'c',
'c' : parseFloat(c)
};
}
// Verificando segunda maior nota
if(primeiroMaior.indice == 'a'){
if(parseFloat(b) >= parseFloat(c)) {
segundoMaior = {
'indice' : 'b',
'b' : parseFloat(b)
}
alert('A sua média é: ' + ((primeiroMaior.a + segundoMaior.b) / 2));
}
}
if(primeiroMaior.indice == 'b'){
if(parseFloat(a) >= parseFloat(c)) {
segundoMaior = {
'indice' : 'a',
'a' : parseFloat(a)
}
alert('A sua média é: ' + ((primeiroMaior.b + segundoMaior.a) / 2));
}
}
if(primeiroMaior.indice == 'c'){
if(parseFloat(b) >= parseFloat(a)) {
segundoMaior = {
'indice' : 'b',
'b' : parseFloat(b)
}
alert('A sua média é: ' + ((primeiroMaior.c + segundoMaior.b) / 2));
}
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.