diff --git a/css/test-section.css b/css/test-section.css new file mode 100644 index 0000000..edfa7b9 --- /dev/null +++ b/css/test-section.css @@ -0,0 +1,61 @@ + +#test { + padding: 10px 0; +} + +.test-text { + text-align: center; +} + +.title { + text-align: center; +} + +.question-num { + margin-top: 20px; + text-align: center; +} + +.question-txt { + height: 100px; + width: 700px; + margin: 50px auto 0; + text-align: center; + font-weight: 200; +} + +#answer-controll { + margin: 10px auto 0; + width: fit-content; + display: flex; + align-items: center; +} + +#answer-controll h1 { + text-align: center; + width: 50px; +} + +.controll-button { + width: 40px; + height: 40px; + cursor: pointer; +} + +.question-controll { + margin: 100px auto 0; + width: 600px; + display: flex; + justify-content: space-between; +} + +.question-controll-button { + font-size: 18px; + width: 125px; + padding: 10px 0; + background-color: none; + border: none; + outline: none; + cursor: pointer; + border-radius: 75px; +} diff --git a/index.html b/index.html index 2a6d723..9a5ff07 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,9 @@ + + + STRESS MASTER @@ -104,160 +107,34 @@

To reduce stress in life of our fellow beings.

-
-

TEST -


-

-

-
On a scale of one to 5, with 5 being the worst, answer the following question:
-


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

How tired do you feel waking up each morning ?

-
- -
-

How often do you experience any of the following symptoms: headaches, chest pain, muscle tension, or nausea?

-
- -
-

How often do you experience fatigue and/or struggle to fall or stay asleep?

-
- -
-

How often do you get irritated by small mishaps ? -

-
- -
-

How often do you wish to run away ?

-
- -
-

How often do you worry excessively about your responsibilities? -

-
- -
-

How often do you struggle to focus on tasks or stay motivated? -

-
- -
-

How often do you feel that even though you have friends to talk to, but you still feel lonely ?

-
- -
-

How often do you regret the choices you have made ? -

-
- -
-

How often do you blame others ?

-
- -
-

How often do you overthink and waste the entire day with only one though clinging on your mind ?

-
- -
-

How much irritated do you feel after a fully packed day with a lot of workload ?

-
- -
-

How often do you experience irritability, sadness, or anger?

-
- -
-

How often do you have little appetite or find that you are overeating?

-
- -
-

How often do you feel that you had overreacted to a particular situation?

-
- -
-
-
RESULT? click on submit.
-
- -
+ + +
+

TEST

+

On a scale of one to 5, with 5 being the worst, answer the following question: +

+ +

+ +

+ +

+ +

+ +
+ +

+ +

+ +
+
+ + +
+
-

CALL TO ACTION


Thinking to talk to someone and want to share your thoughts.


diff --git a/js/test-section.js b/js/test-section.js new file mode 100644 index 0000000..7b4994e --- /dev/null +++ b/js/test-section.js @@ -0,0 +1,154 @@ +const questions = [ + { + q: 'How tired do you feel waking up each morning ?', + a: 1 + }, + { + q: 'How often do you experience any of the following symptoms: headaches, chest pain, muscle tension, or nausea?', + a: 1 + }, + { + q: 'How often do you experience fatigue and/or struggle to fall or stay asleep?', + a: 1 + }, + { + q:'How often do you get irritated by small mishaps ?', + a: 1 + }, + { + q: 'How often do you wish to run away ?', + a: 1 + }, + { + q: 'How often do you worry excessively about your responsibilities?', + a: 1 + }, + { + q: 'How often do you struggle to focus on tasks or stay motivated?', + a: 1 + }, + { + q: 'How often do you feel that even though you have friends to talk to, but you still feel lonely ?,', + a: 1 + }, + { + q: 'How often do you regret the choices you have made ?', + a: 1 + }, + { + q: 'How often do you blame others ?', + a: 1 + }, + { + q: 'How often do you overthink and waste the entire day with only one though clinging on your mind ?', + a: 1 + }, + { + q: 'How much irritated do you feel after a fully packed day with a lot of workload ?', + a: 1 + }, + { + q: 'How often do you experience irritability, sadness, or anger?', + a: 1 + }, + { + q: 'How often do you have little appetite or find that you are overeating?', + a: 1 + }, + { + q: 'How often do you feel that you had overreacted to a particular situation?', + a: 1 + } +] + +let answer = 1 +let currentQuestion = 0 +let currentScore = 0 +const $questionNum = document.getElementById('question-num') +const $question = document.getElementById('question') +const $answer = document.getElementById('answer') + +// Rendering Question Max and Current +const renderQuestionNum = (currentQuestionIndex, maxQuestion) => { + $questionNum.innerText = `${currentQuestionIndex + 1} / ${maxQuestion}` +} + +// Rendering Question Based On Param +const renderQuestion = (questionNumber) => { + $question.innerText = questions[questionNumber].q +} + +// Render Answer Based On Param +const renderAnswer = (answer) => { + $answer.innerText = answer +} + +// Inc Button Logic +const $incButton = document.getElementById('inc-button') +$incButton.onclick = () => { + if (answer === 5) return null + answer++ + renderAnswer(answer) +} + +// Decr Button Logic +const $decrButton = document.getElementById('decr-button') +$decrButton.onclick = () => { + if (answer === 1) return null + answer-- + renderAnswer(answer) +} + +// Next Button Logic +const $nextButton = document.getElementById('next-question-button') +$nextButton.onclick = () => { + const parsedInt = parseInt($answer.innerText) + // Check If Its Valid + if (Number.isNaN(parsedInt)) return alert('Something is Error') + questions[currentQuestion].a = parsedInt + + // Submit Logic + if (currentQuestion + 1 === questions.length) { + const eachScore = questions.map(question => question.a) + const scores = eachScore.reduce((prev,current) => prev + current) + + return alert(scores) + } + + // Next QUestion Logic + + answer = 1 + currentQuestion++ + renderAnswer(questions[currentQuestion].a) + renderQuestion(currentQuestion) + renderQuestionNum(currentQuestion, questions.length) + + // If This is the last question + if (currentQuestion + 1 === questions.length) { + $nextButton.innerText = 'Submit' + } +} + +const $prevButton = document.getElementById('prev-question-button') +$prevButton.onclick = () => { + const parsedInt = parseInt($answer.innerText) + // Check If Its Valid + if (Number.isNaN(parsedInt)) return alert('Something is Error') + currentQuestion-- + answer = questions[currentQuestion].a + renderAnswer(questions[currentQuestion].a) + renderQuestion(currentQuestion) + renderQuestionNum(currentQuestion, questions.length) + + // Changing nextButton innerText + if ($nextButton.innerText === 'Submit') { + $nextButton.innerText = 'Next' + } +} + + + +// For first time render +renderQuestionNum(currentQuestion, questions.length) +renderQuestion(currentQuestion) +renderAnswer(questions[currentQuestion].a) \ No newline at end of file