-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
144 lines (115 loc) · 4.88 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PercentageMaker</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<h2 class="text-center p-1">Percentage Maker</h2>
<div class="container-md check"></div>
<div class="container-md check">
<div class="mb-3">
<label for="total-questions" class="form-label">Total Questions you have</label>
<input type="number" class="form-control" id="total-questions" aria-describedby="emailHelp">
<div class="form-text">Enter the total questions number you have.</div>
</div>
<div class="row">
<div class="col">
<input type="number" class="form-control" id="startingfrom" placeholder="Starting from">
</div>
<div class="col">
<input type="number" class="form-control" id="endwith" placeholder="Ended with">
</div>
</div>
<div class="mb-3">
<label for="percentageFrom" class="form-label">Percentage From</label>
<input type="number" placeholder="100" class="form-control" id="percentageFrom" aria-describedby="emailHelp">
</div>
<div class="mb-3 form-check">
<input type="checkbox" id="createHalves" value="createHalves" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Create halves</label>
</div>
<button href="#answers" id="create" class="btn btn-primary">Create Percentages</button>
</div>
<!-- ================================ form finished ========================================= -->
<div class="container-md check mt-3 d-flex flex-wrap" id="answers">
</body>
<style>
.myCard{
border: 1px solid rgb(30, 30, 30);
margin: 2px;
border-radius: 3px;
display: flex;
justify-content: center;
align-items: center;
width: 18%;
padding-bottom: -5px;
}
.fw-semibold , p{
margin-bottom:0 !important;
padding-bottom:0 !important;
}
</style>
<script>
let totalQuestions;
let answers = document.getElementById('answers');
let createHalves;
document.getElementById('create').addEventListener('click' , (e)=>{
console.log('clicked')
totalQuestions = document.getElementById('total-questions').value *1
let startingfrom = document.getElementById('startingfrom')
let endwith = document.getElementById('endwith')
createHalves = document.getElementById('createHalves').checked;
if(startingfrom.value ==0){
startingfrom.value = 1;
}
if(endwith.value ==0){
endwith.value = totalQuestions;
}
if(startingfrom > endwith){
let temp = startingfrom.value;
startingfrom.value = endwith.value;
endwith.value = temp;
}
console.log(totalQuestions)
for (let index = startingfrom.value*1; index <= endwith.value*1; index++) {
console.log("Question number : " , index , " ", getPercentage(index))
createCard(index);
}
})
console.log('hafv : ' ,createHalves)
function createCard(num){
// Create the card element
const card = document.createElement('div');
card.className = 'myCard';
// Create the first paragraph element
const p1 = document.createElement('p');
p1.className = 'fw-semibold fs-5';
p1.textContent = `${num.toString().padStart(2, '0')} :`;;
// Create the second paragraph element
const p2 = document.createElement('p');
p2.textContent = `${getPercentage(num).toString().padStart(2, '0')}`;
// Create the third paragraph element
const p3 = document.createElement('p');
p3.className = 'text-secondary';
p3.innerHTML = ` ${getPercentage(num+0.5).toString().padStart(2, '0')}`;
// Append the paragraphs to the card
card.appendChild(p1);
if(createHalves){
card.appendChild(p2);
}
card.appendChild(p3);
answers.appendChild(card);
}
percentageFrom = document.getElementById('percentageFrom').value*1;
function getPercentage(num){
console.log('num',num)
console.log('totalQuestions',totalQuestions)
console.log('percentageFrom',percentageFrom)
return Math.floor(num/totalQuestions*100)
}
</script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</html>