Hi there, is there any reason the following code would not go to the “CORRECT” chapter. I am using the following values for answers:

# samples: 29

mean: 0.3089
std dev: 0.0849

P statistic: 0.56
Critical Region: [0.27, 0.33]

As per the formulae these answers should be correct in the code but I am always returned “INCORRECT” instead

``````/* ***** Link to download the Simio project ****** */\
<a href="https://pennstateoffice365-my.sharepoint.com/:u:/g/personal/oma110_psu_edu/EVYD97oU01FGtuN1vEvz_tUBcT3GJKXvowIpRATCr9OiyQ?e=Ug33NB" target="_blank">Simio</a>

//After observing the system, enter your sample size, mean, and standard deviation. Before performing the hypothesis test(s), click "CHECK MY OBSERVATIONS" below to see if your observations fall within an acceptable range. If they do not, recollect data until your observations satisfy the requirements for a realistic sample.//

What were your observed values from the system?

Number of Samples Observed: <<textbox "\$n" "">>
Mean of PREPARATION station processing time (minutes): <<textbox "\$x" "">>
Standard Deviation of PREPARATION station processing time (minutes): <<textbox "\$s" "">>

<<set \$i=3>>
<<if 0.27 <= \$x && \$x <= 0.33 and 0.06 <= \$s && \$s <= 0.1 and 20 <= \$n && \$n <= 29>>
<<if \$i == 3>>
<<set \$scores = \$scores + 1.0>>
<<else>>
<<set \$scores = \$scores + 0>>
<</if>>
<<set \$ts = ((\$x - 0.3) / (\$s / Math.sqrt(\$n))).toFixed(2)>>
<<set \$cR_u = (0.3 + (2.045 * (\$s / Math.sqrt(\$n)))).toFixed(2)>>
<<set \$cR_l =  (0.3 - (2.045 * (\$s / Math.sqrt(\$n)))).toFixed(2)>>
Great! Report your hypothesis testing results for the PREPARATION station (minutes):
<span id="choice">
PREPARATION STATION~N(0.3,0.1100)

/* **** set up the dropboxes for first question ***** */\
<<listbox "\$response1">>
<<option "Fail to Reject">>
<<option "Reject">>
<</listbox>> H0: µ = 0.3 minutes based on a <<listbox "\$response2">>
<<option "Z-test">>
<<option "t-test">>
<<option "paired t-test">>
<<option "chi-squared test">>
<<option "f-test">>
<<option "proportions test">>
<</listbox>>
\
<<if \$visited eq 1>>\
<<set \$j=3>>\
<</if>>\
You have \$j chances total.
<<if \$j eq 0>>
[[CORRECT|Chapter44.1.1.1]]
<</if>>
\
/* **** set up the limitations *** */\
<<set \$j = \$j-1>>\
<<if \$j gte 0>>\
<<set \$visited = 0>>\
<span id="choice">
Test Statistic: <<textbox "\$response3" "">>

P-Value: <<textbox "\$response4" "">>

Critical Region: [ <<textbox "\$response5" "">>,  <<textbox "\$response6" "">> ]

<<button "Submit">>

<<print ""+\$response1+" H0: µ0 = µ1 based on a "+\$response2+"">>
\
<<set \$ts_UB = \$ts + 0.1>>
<<set \$ts_LB = \$ts - 0.1>>
<<set \$cR_u_UB = \$cR_u + 0.1>>
<<set \$cR_u_LB = \$cR_u - 0.1>>
<<set \$cR_l_UB = \$cR_l + 0.1>>
<<set \$cR_l_LB = \$cR_l - 0.1>>
/* ****set the condition to check for all answers **** */\
<<if \$response1 is "Fail to Reject" and \$response2 is "t-test" and \$response3 gte \$ts_LB and \$response3 lte \$ts_UB and \$response4 gte 0.0501 and \$response4 lte 1 and \$response5 gte \$cR_u_LB and \$response5 lte \$cR_u_UB and \$response6 gte \$cR_l_LB and \$response6 lte \$cR_l_UB>>
/****  Add the score here **** */\
<<set \$chance = \$j>>
<<if \$j eq 2>>
<<set \$scores = \$scores + 5>>
<<elseif \$j eq 1>>
<<set \$scores = \$scores + 4>>
<<elseif \$j eq 0>>
<<set \$scores = \$scores + 3>>
<<endif>>
\
[[CORRECT|Chapter44.1.1.1]]
<<else>>
[[INCORRECT|Chapter43.1.1.1.1]]
<<endif>>
<</replace>>
<</button>>
</span>
<<endif>>
<<else>>
<<popover 'noclick'>>Your sample data does not accurately represent the sample. Please take the following into account and recalculate your sample data:
- t-tests use sample sizes n<30 and Z-tests use sample sizes n>=30. When possible, larger sample sizes are more effective.
- Make sure you are observing data based on the SIMULATION time (the rate at which the simulation is run can be adjusted in the top ribbon)
- Try taking your sample during a different point in the simulation. Wait at least 3 days to collect any data to avoid the system's warm-up period<</popover>><</if>>
<<set \$i = \$i - 1>>
``````

I’d like to share a simple debugging procedure that may help you solve the problem.

When conditions aren’t being met, the first culprit is usually the variables that you are checking.

1.) Output variables just before each condition. Are they what you expected them to be? (Sometimes, a string can look like a number – check the type as well.)

2.) Output a visible flag of sorts just after each condition when dealing with nested conditions. Which condition is failing? It might be a previous one that affects others down the road – outputting variables should reveal this though.)

3.) Reduce the complexity. Comment out code that’s unnecessary and might be interfering with your debugging. You can also reduce the complexity of your multi-part condition statements. (Which sub-condition is failing? – check each one individually and see.)

4.) Check your syntax. Syntax errors are very common, especially in condition statements. (A missing closing `<</if>>` is also common and hard to detect.)

5.) Check your order of logic. Sometimes we put the cart before the horse.

Have you tried these steps? Doing so methodically will reveal the error practically every time.

1 Like

The problem is that the values obtained from the textboxes will be strings. For the inequalities to work, you’ll first need to convert `\$n`, `\$x`, and `\$s` from strings to floats, which you can do like this:

``````<<set \$n to parseFloat(\$n)>>
``````
3 Likes

You ruined the surprise.

1 Like

Further to svlin’s answer, as well as converting to floats, I would check the values are approximately equal, rather than exact, just in case they get rounded differently.

As long as `answer` is not zero do something like this…

``````error = Math.abs((answer - guess) / answer)
if error < 0.001
...
``````

https://0.30000000000000004.com/

And here (long)

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

2 Likes

1 Like

So now the block i have converted all of the variables to floats, but the result when i test is the same

``````/* ***** Link to download the Simio project ****** */\
<a href="https://pennstateoffice365-my.sharepoint.com/:u:/g/personal/oma110_psu_edu/EVYD97oU01FGtuN1vEvz_tUBcT3GJKXvowIpRATCr9OiyQ?e=Ug33NB" target="_blank">Simio</a>

//After observing the system, enter your sample size, mean, and standard deviation. Before performing the hypothesis test(s), click "CHECK MY OBSERVATIONS" below to see if your observations fall within an acceptable range. If they do not, recollect data until your observations satisfy the requirements for a realistic sample.//

What were your observed values from the system?

Number of Samples Observed: <<textbox "\$n" "">>
Mean of PREPARATION station processing time (minutes): <<textbox "\$x" "">>
Standard Deviation of PREPARATION station processing time (minutes): <<textbox "\$s" "">>

<<set \$n to parseFloat(\$n)>>
<<set \$x to parseFloat(\$x)>>
<<set \$s to parseFloat(\$s)>> // NEW CODE

<<set \$i=3>>
<<if 0.27 <= \$x && \$x <= 0.33 and 0.06 <= \$s && \$s <= 0.1 and 20 <= \$n && \$n <= 29>>
<<if \$i == 3>>
<<set \$scores = \$scores + 1.0>>
<<else>>
<<set \$scores = \$scores + 0>>
<</if>>
<<set \$ts = ((\$x - 0.3) / (\$s / Math.sqrt(\$n))).toFixed(2)>>
<<set \$cR_u = (0.3 + (2.045 * (\$s / Math.sqrt(\$n)))).toFixed(2)>>
<<set \$cR_l =  (0.3 - (2.045 * (\$s / Math.sqrt(\$n)))).toFixed(2)>>
Great! Report your hypothesis testing results for the PREPARATION station (minutes):
<span id="choice">
PREPARATION STATION~N(0.3,0.1100)

/* **** set up the dropboxes for first question ***** */\
<<listbox "\$response1">>
<<option "Fail to Reject">>
<<option "Reject">>
<</listbox>> H0: µ = 0.3 minutes based on a <<listbox "\$response2">>
<<option "Z-test">>
<<option "t-test">>
<<option "paired t-test">>
<<option "chi-squared test">>
<<option "f-test">>
<<option "proportions test">>
<</listbox>>
``````

You need to make sure that the variables are converted to floats after the user inputs the numbers, not before. As it is, the code you added only runs when the passage is loaded. To make it work, you should put the code inside the `<<link>>`, like this:

``````<<link "CHECK MY OBSERVATIONS">><<replace "#test">>
<<set \$n to parseFloat(\$n)>>
<<set \$x to parseFloat(\$x)>>
<<set \$s to parseFloat(\$s)>>
``````

Good catch.

Perhaps I’ve missed something here, but why are you using `<<textbox>>`, which yields strings, instead of `<<numberbox>>`, which yields numbers?

1 Like