-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Rakesh9100:main' into update-word-count-calculator
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# <p align="center">Probability Calculator</p> | ||
|
||
## Description :- | ||
|
||
Calculates the Probability of different events based on user input. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/a5f8aa5e-0775-46f9-9f26-69bb8c734c18) | ||
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/d769fcc3-4abd-43f2-8d5e-65d05b0f8fdd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Probability Calculator</title> | ||
<style> | ||
body { | ||
background-repeat: none; | ||
background-position:center; | ||
font-family: Arial, sans-serif; | ||
background-size: cover; | ||
margin: 0; | ||
padding: 0; | ||
background-color:rgb(45, 191, 228); | ||
object-fit: cover; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 50px auto; | ||
padding: 20px; | ||
background-color: #fff; | ||
border-radius: 10px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
h2 { | ||
text-align: center; | ||
color: #333; | ||
} | ||
label { | ||
display: block; | ||
margin-bottom: 10px; | ||
} | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
button { | ||
display: block; | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
button:hover { | ||
background-color: #0056b3; | ||
} | ||
#result { | ||
margin-top: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Probability Calculator</h2> | ||
<label for="option">Select Option:</label> | ||
<select id="option" onchange="showInputs()"> | ||
<option value="">Select</option> | ||
<option value="coins">Different Probabilities in Coins</option> | ||
<option value="dices">Different Probabilities in Dices</option> | ||
<option value="events">Different Probabilities in Two Events</option> | ||
</select> | ||
<div id="inputs" style="display: none;"> | ||
<!-- Input fields will be dynamically added here based on user's selection --> | ||
</div> | ||
<button onclick="calculate()">Calculate</button> | ||
<div id="result"></div> | ||
</div> | ||
|
||
<script> | ||
function showInputs() { | ||
var option = document.getElementById("option").value; | ||
var inputsDiv = document.getElementById("inputs"); | ||
inputsDiv.innerHTML = ""; | ||
|
||
if (option === "coins") { | ||
inputsDiv.innerHTML = '<label for="numCoins">Number of Coins (1-3):</label>' + | ||
'<select id="numCoins">' + | ||
'<option value="1">1</option>' + | ||
'<option value="2">2</option>' + | ||
'<option value="3">3</option>' + | ||
'</select>'; | ||
} else if (option === "dices") { | ||
inputsDiv.innerHTML = '<label for="numDices">Number of Dices (1-2):</label>' + | ||
'<select id="numDices">' + | ||
'<option value="1">1</option>' + | ||
'<option value="2">2</option>' + | ||
'</select>'; | ||
} else if (option === "events") { | ||
inputsDiv.innerHTML = '<label for="probEvent1">Probability of Event A(Between 0 and 1):</label>' + | ||
'<input type="number" id="probEvent1" step="0.01">' + | ||
'<label for="probEvent2">Probability of Event B:(Between 0 and 1)</label>' + | ||
'<input type="number" id="probEvent2" step="0.01">'; | ||
} | ||
|
||
if (option) { | ||
inputsDiv.style.display = "block"; | ||
} else { | ||
inputsDiv.style.display = "none"; | ||
} | ||
} | ||
|
||
function calculate() { | ||
var option = document.getElementById("option").value; | ||
var resultDiv = document.getElementById("result"); | ||
var resultText = ""; | ||
|
||
if (option === "coins") { | ||
var numCoins = parseInt(document.getElementById("numCoins").value); | ||
resultText = "Calculating probabilities for " + numCoins + " coin(s) toss...<br>"; | ||
if (numCoins == 1) { | ||
resultText += "Probability of Getting Head= 0.5<br>Probability of Getting Tails= 0.5"; | ||
} else if (numCoins == 2) { | ||
resultText += "Probability of Getting 1 Head and 1 Tails= 0.33<br>Probability of Getting 2 Tails= 0.33<br>Probability of Getting 2 Heads= 0.33"; | ||
} else if (numCoins == 3) { | ||
resultText += "Probability of Getting 1 Head and 2 Tails= 3/8<br>Probability of Getting 1 Tails and 2 Heads= 3/8<br>Probability of Getting 3 Heads= 1/8<br>Probability of Getting 3 Tails= 1/8"; | ||
} | ||
} else if (option === "dices") { | ||
var numDices = parseInt(document.getElementById("numDices").value); | ||
resultText = "Calculating probabilities for " + numDices + " dice(s) throw...<br>"; | ||
if (numDices == 1) { | ||
resultText += "Probability of Getting 1=1/6<br>Probability of Getting 2=1/6<br>Probability of Getting 3=1/6<br>Probability of Getting 4=1/6<br>Probability of Getting 5=1/6<br>Probability of Getting 6=1/6<br>Probability of Getting even number=1/2<br>Probability of Getting odd number=1/2"; | ||
} else if (numDices == 2) { | ||
resultText += "Probability of Getting even Number on both Dices=1/4<br>Probability of Getting odd Number on both Dices=1/4<br>Probability of Getting Same number on both Dices=1/6<br>Probability of Getting different number on both Dices=5/6<br>Probability of Getting First value more than second value=5/12"; | ||
} | ||
} else if (option === "events") { | ||
var probEvent1 = parseFloat(document.getElementById("probEvent1").value); | ||
var probEvent2 = parseFloat(document.getElementById("probEvent2").value); | ||
resultText = "Calculating probabilities for two events with probabilities: " + probEvent1 + " and " + probEvent2+":-<br>"+"1)Probability of event A NOT occuring: P(A')="+ (1-probEvent1)+".<br>"+"2)Probability of event B NOT occuring: P(B')="+ (1-probEvent2)+".<br>"+"3)Probability of event A and event B both occuring: P(A∩B)="+ (probEvent1*probEvent2)+".<br>"+"4)Probability that A or B or both occur: P(A∪B)="+(probEvent2+probEvent1-(probEvent1*probEvent2))+".<br>"+"5)Probability that A or B occurs but NOT both: P(AΔB)="+((probEvent2+probEvent1-(2*probEvent1*probEvent2)))+".<br>"+"6)Probability of neither A nor B occuring: P((A∪B)="+(1-(probEvent2+probEvent1-(probEvent1*probEvent2)))+".<br>"+"7)Probability of A occuring but NOT B="+(probEvent1*(1-probEvent2))+".<br>"+"8)Probability of B occuring but NOT A="+(probEvent2*(1-probEvent1))+"."; | ||
|
||
} else { | ||
resultText = "Please select an option."; | ||
} | ||
|
||
|
||
resultDiv.innerHTML = resultText; | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters