Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Zeros are replaced in free response if typed at the first position

Hi there,

Sorry for the maybe confusing title of my question. First maybe some background: I'm conducting an online study that infrequently asks participants to report numbers that they have recently seen. The numbers range from 0 to 9 and participants can report up to 4 numbers.

I adapted a script proposed by Sebastiaan in another post. The script is as follows:

{console.log(vars.response)

if (vars.response in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) {

vars.multichar_response += vars.response.toString()

} else if (vars.response === 'backspace') {

vars.multichar_response = vars.multichar_response.toString().slice(0, vars.multichar_response.toString().length - 1)

} else if (vars.response !== 'enter') {

vars.multichar_response += vars.response

}

}

Now it has come to my attention, that when participants type a "0" first and then some other numbers, the 0 is overwritten by the subsequent number. However, if participants report a 0 alone or in between other numbers, everything works just fine.

Does anyone have a suggestion how I can adapt the script so that also zeros remain when typed in first and are then followed by other numbers?

Thanks a lot already in advance!

Best,

Christian

Comments

  • Hi Christian,

    this is a typical problem that comes with your variable type.

    Your variable is set as a number. Numbers do not start with a zero. If you manage to change the variable type to character/string (which means letters or names) this should not happen.

    Another option would be to make it a list of numbers.

    var = 012 --> saves as var = 12

    var = '012' --> saves as var = '012' keep in mind that you are not working with a number any more. So, '012' - 10 is not possible. It treats '012' like a word. You cannot substract numbers from words ;)

    var = [0,1,2] --> is a list of three numbers. --> I will need to learn JavaScript. In python you could use 'append', so the number of items in the list does not have to be the same.

    Hope that helps you out.

    Stephan

  • Hi @ChristianB ,

    As @DahmSF pointed out, it has to do with the type of variable. I'm no Javascript expert, but I think that it would be straightforward with pure Javascript variables.

    However, I think the problem here might be with how OS handles the variables declared with vars.. It looks as if for some reason it won't treat it as numerical if it contains only digits and no alphanumerical characters.

    The problem appears not to be when registering the first response, but when registering the next one. If the second response is a digit, then the leading 0 disappears (it seems that OS then considers that vars.multichar_response is a numerical variable of sort). I've adapted your code to allow the response "a", If you first type "0" and then "a", you'll see that vars.multichar_response actually contains "0a" (string variable)! However, if you typed "0", "1" and then "a", vars.multichar_response would first be equal to "0", "1" and then "1a".

    I played around a bit and modified your code to:

    console.log("REPSONSE:"+vars.response)
    if (vars.response in [0,1, 2, 3, 4, 5, 6, 7, 8, 9, 'a'] && vars.multichar_response!="") {
    vars.multichar_response += vars.response.toString()
    } else if (vars.response==0 && vars.multichar_response=="") {
    console.log("Leading zero detected")
    vars.leading_zero="y"
    vars.multichar_response="0"
    } else if (vars.response === 'backspace') {
    vars.multichar_response = vars.multichar_response.toString().slice(0,vars.multichar_response.toString().length - 1)
    } else if (vars.response !== 'enter') {
    vars.multichar_response += vars.response
    }
    if (vars.leading_zero=="y" && vars.multichar_response.toString().length>0){
    var responsestring = vars.multichar_response.toString().padStart(vars.multichar_response.toString().length+1,'0')
    } else {
    var responsestring=vars.multichar_response
    }
    vars.multichar2=responsestring
    console.log("RESPONSE STRING LENGTH: "+responsestring.length)
    console.log("RESPONSE STRING: "+responsestring)
    console.log("MULTICHAR_RESPONSE LENGTH: "+vars.multichar_response.toString().length)
    console.log("MULTICHAR_RESPONSE: "+vars.multichar_response)
    console.log("MULTICHAR2 "+vars.multichar2)
    

    (having set vars.multichar_response to "" before the loop begins)

    I'm setting up an actual Javascript variable (var responsestring) as opposed to declaring it using the vars. method. When doing so, I can use code to detect when a leading zero is typed and if it is, use the .padStart function applied to the .toString function of the vars.multichar_response variable. You'll see that responsestring does work and contain all digit responses including the leading zero.

    The minute I try to pass it onto a newly created vars.multichar2 variable, the leading zero disappears (unless the content of vars.multichar2 contains at least one alphanumerical character somewhere).

    You can try out the example I worked on. Check out the console to monitor everything going on.

    In summary, I couldn't work out how to keep a leading zero as part of a variables declared with the vars. method. I think the problem is not a Javascript one but has to do with the way OS interfaces with Javascript to handle variables.

    Perhaps the developers can shed some more light on this (I'm tagging @sebastiaan in case he or someone else on the team have suggestions to solve this issue).

    The only thing I can think for now is to use a variable to detect whether there is a leading zero (as I've done in the code above) and then save that information in the data log, so that you can afterwards know that participants actually pressed zero first and add it in the data set afterwards (or is your program has to do different things if participants start with zero, you can use that variable to that effect). If you need to display the participants' responses on the screen as they type, you could use two distinct feedback objects, condition their presentation on the value of whatever variable you use to detect if there is a leading zero, and on the feedback object to be show when that is the case, display "0[multichar_response]" instead of "[multichar_response]" (as I've done in the example above).


    So, unsolved, but I hope that the above helps you to find a workaround solution...

    Perhaps other users with greater experience of Javascript and OS will have better solutions!

    Fab.

    Buy Me A Coffee

  • Hi @eduard,

    Thanks for this! That makes sense 👍️

    Fabrice.

    Buy Me A Coffee

  • Hi @ChristianB,

    As an afterthought... One thing you could do is to accept the "0" (zero) as input but save an "O" (o letter) into vars.multichar_response. Perhaps it works out well in your design. Depending on what font you use on the screen, subjects would not see the difference between "O" and "0"...

    Try editing the code in my example above and replace "0" by "O"...

    Best,

    Fabrice.

    Buy Me A Coffee

  • Sorry for my late response.

    Thank you all for your Input. Quite an obvious oversight on my side. However, with your input, I was able to fix the issue! :)

    Best,

    Christian

  • Hi @ChristianB and @Fab ,

    I see it's already been resolved 👍️

    Another way would've been to initialize the variable with something that actually isn't shown, but that does prevent the string from being converted to a number. For example, a   (non-breaking space):

    vars.my_var = ' '
    vars.my_var += '0'
    vars.my_var += '1'
    console.log(vars.my_var)
    

    — Sebastiaan

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games