jeudi 2 septembre 2021

Javascript If /if else/ else - not sure what to use

I'm not great at JS, but I've got some code here, and basically, I want the first round of code to execute for the RowIndex 1,2,3,4,5 and take the reaction time from 8000ms. If the rows are 6,7,8,9,10 then I want the reaction time to be taken from only 1500ms.

Here is the code I have:

gorillaTaskBuilder.onScreenStart((spreadsheet: any, rowIndex: number, screenIndex: number, row: any, container: string) => {
$('body').css('background-color', BACKGROUND_COLOUR);
$('h1, h2, h3, h4, h5, p, span').css('color', TEXT_COLOUR);
if (row.display == _requiredFeedbackDisplay) {
    if (screenIndex == _requiredFeedbackScreen) {
        if (rowIndex == 1,2,3,4,5) {
            // Retrieve the reaction time from the store
            var lastRT: number = gorilla.retrieve(_RTKey, null, false);
            var roundedRT: number = Math.round(lastRT);
            var pointConvertedBlue: number = (8000 - roundedRT);
            // We now add the rounded reaction time to the screen
            $(container + _requiredFeedbackZoneSelector).html('<h1>' + '<p style="color: white;">' + 'You earned ' + pointConvertedBlue + ' points' + '</p> ' + '</h1>');
            // Using gorilla.refreshLayout here will make sure that everything is displayed nicely on the screen
            gorilla.refreshLayout();
            gorilla.metric({
                    trial_number: 'pointConvertedBlue',
                    response: pointConvertedBlue
        
 });
                else (rowIndex == 6,7,8,9,10) {
                        // Retrieve the reaction time from the store
                        var pointConvertedRed: number = (1500 - roundedRT);
                        // We now add the rounded reaction time to the screen
                        $(container + _requiredFeedbackZoneSelector).html('<h1>' + '<p style="color: white;">' + 'You earned ' + pointConvertedRed + ' points' + '</p> ' + '</h1>');
                        // Using gorilla.refreshLayout here will make sure that everything is displayed nicely on the screen
                        gorilla.refreshLayout();
                        gorilla.metric({
                            trial_number: 'pointConvertedRed',
                            response: pointConvertedRed
                        
                            
                        }
                     
        
    


                        });

If I delete the block of code starting from the else statement, the first block works fine. When I have both blocks together, the script only runs the second block of code. This is probably a really easy fix but I'm absolutely stuck haha.

Aucun commentaire:

Enregistrer un commentaire