Skip to content
Snippets Groups Projects
Commit 766054aa authored by Vukile Langa's avatar Vukile Langa
Browse files

feat(components): negative numbers in numerical queations

parent 0712b74d
No related branches found
No related tags found
1 merge request!579Negative numerical type
...@@ -13,6 +13,7 @@ const ValueContainer = styled.div` ...@@ -13,6 +13,7 @@ const ValueContainer = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-right: 25px; margin-right: 25px;
label { label {
font-size: 12px; font-size: 12px;
} }
...@@ -66,7 +67,8 @@ const ExactAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -66,7 +67,8 @@ const ExactAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
const onlyNumbers = value => { const onlyNumbers = value => {
return value return value
.replace(/[^0-9.]/g, '') .replace(/[^-?0-9.]/g, '')
.replace(/(?<!^)-/g, '')
.replace(/(\..*?)\..*/g, '$1') .replace(/(\..*?)\..*/g, '$1')
.replace(/^0[^.]/, '0'); .replace(/^0[^.]/, '0');
}; };
...@@ -124,11 +126,14 @@ const ExactAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -124,11 +126,14 @@ const ExactAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
}; };
// SUBMIT // SUBMIT
const exactMultMargin = parseFloat((exact * marginError) / 100); const exactMultMargin = Math.abs(parseFloat((exact * marginError) / 100));
const castExactStudent = ['-', '-.', '.'].includes(exactStudent)
? 0
: Number(exactStudent);
const computedMaxValue = Number(exactMultMargin) + Number(exact); const computedMaxValue = Number(exactMultMargin) + Number(exact);
const computedMinValue = Number(exact) - Number(exactMultMargin); const computedMinValue = Number(exact) - Number(exactMultMargin);
const isCorrect = !!( const isCorrect = !!(
exactStudent <= computedMaxValue && exactStudent >= computedMinValue castExactStudent <= computedMaxValue && castExactStudent >= computedMinValue
); );
return ( return (
......
...@@ -13,6 +13,7 @@ const ValueContainer = styled.div` ...@@ -13,6 +13,7 @@ const ValueContainer = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-right: 25px; margin-right: 25px;
label { label {
font-size: 12px; font-size: 12px;
} }
...@@ -66,7 +67,7 @@ const PreciseAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -66,7 +67,7 @@ const PreciseAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
const onlyNumbers = value => { const onlyNumbers = value => {
return value return value
.replace(/[^0-9.;]/g, '') .replace(/[^-?0-9.;]/g, '')
.replace(/(\..*?)\..*/g, '$1') .replace(/(\..*?)\..*/g, '$1')
.replace(/^0[^.]/, '0'); .replace(/^0[^.]/, '0');
}; };
...@@ -158,7 +159,7 @@ const PreciseAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -158,7 +159,7 @@ const PreciseAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
)} )}
{readOnly && showFeedBack && ( {readOnly && showFeedBack && (
<ResultContainer> <ResultContainer>
<span>{`(Accepted Answers : ${precise.replaceAll(';', ' -')})`}</span> <span>{`(Accepted Answers : ${precise.replaceAll(';', '; ')})`}</span>
<span> <span>
Answer:{' '} Answer:{' '}
<FinalResult isCorrect={isCorrect}> <FinalResult isCorrect={isCorrect}>
......
...@@ -13,6 +13,7 @@ const ValueContainer = styled.div` ...@@ -13,6 +13,7 @@ const ValueContainer = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-right: 25px; margin-right: 25px;
label { label {
font-size: 12px; font-size: 12px;
} }
...@@ -70,7 +71,8 @@ const RangeAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -70,7 +71,8 @@ const RangeAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
const onlyNumbers = value => { const onlyNumbers = value => {
return value return value
.replace(/[^0-9.]/g, '') .replace(/[^-?0-9.]/g, '')
.replace(/(?<!^)-/g, '')
.replace(/(\..*?)\..*/g, '$1') .replace(/(\..*?)\..*/g, '$1')
.replace(/^0[^.]/, '0'); .replace(/^0[^.]/, '0');
}; };
...@@ -128,10 +130,12 @@ const RangeAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => { ...@@ -128,10 +130,12 @@ const RangeAnswerComponent = ({ node, readOnly, testMode, showFeedBack }) => {
}; };
// SUBMIT // SUBMIT
const castExactStudent = ['-', '-.', '.'].includes(rangeStudentValue)
? 0
: Number(rangeStudentValue);
const isCorrect = !!( const isCorrect = !!(
Number(rangeStudentValue) <= Number(maxValue) && castExactStudent <= Number(maxValue) && castExactStudent >= Number(minValue)
Number(rangeStudentValue) >= Number(minValue)
); );
return ( return (
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment