So I've managed to make a simple and easy quiz with Javascript, mainly with an array with both questions and answers (as of now, only numbers).
['How many moons does Earth have?', 1],
['How many moons does the saturn have?', 31],
['How many moons does venus have?',0]
I also have a function that adds to the score if the answer is right.
function asQuestion(question) {
var answer = prompt(question[0], '');
if (answer == question[1]) {
score++;
}
For now, I only have prompts, which is a bit tacky and not quite what I wanted. What I'm looking for is, how can I store those questions with multiple answers (only one of which is correct)? And is it possible to, instead of using prompts, use a <p>, literal or a form, to write these questions, hit button, fadeOut the answered question, and give a new one?
(Example: Question 1: Radio1(What is the capitol of Finland) Radio2(What is the biggest ocean). I check radio 1, and hit 'Next Question'.
Just looking for some advice, tips and guidance as I am quite new to Javascript and jQuery. I really appreciate all the help I can get. =)
Your question is a bit too broad for Stack Overflow, but here are a few guidelines.
Yes, all you said is possible! You can start from something as simple as:
['How many moons does Earth have?', 1, 0, 2, 3]
knowing that the first answer is correct and shuffling them for your presentation.
You can even make a separate button for each answer (improving the UX by getting rid of a redundant click) but beware of accidental clicks in that case. It's all up to you.
Here is a super-simple quiz I made for you: http://jsfiddle.net/rTv97/ There are millions of ways to improve it, of course. But it should get you started.
Note the system I used:
['How many moons does the saturn have?', 1, 31, 35, 29, 48]
\ / ^ \ /
text correct answers
It goes: question text, correct answer index (one-based), answers.
So, number 1 here means the the first of the 4 answers (31, 35, 29, 48) is correct.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
Given any array of numbers, similar in nature to the following:
[48, 60, 64, 67, 72]
I want to be able to evaluate this(or any) series of numbers and look for musically meaningful patterns, and I'm not sure how to start going about it.
For example, if I subtract 48 from every number I would get this:
[0, 12, 16, 19, 24]
...one will notice that the 1st, 2nd and 5th numbers are 12 apart from each other, which is a meaningful pattern in music, as 12 steps is one octave. This is one of the things I would want to be able to figure out by just looking at the numbers.
Now, if I take the middle three numbers and subtract 12 from each one I get:
[0, 4, 7]
...which is the numerical pattern of steps on a keyboard that would create a Major Triad, which is another example of something I would want to be able to evaluate from a series of numbers.
So, in the end, the original series of numbers:
[48, 60, 64, 67, 72]
...represents the following musical notes:
[`C2`, `C3`, `E3`, `G3`, `C4`]
...which is a C Major Triad C3, E3, G3 with the root doubled down one octave C2 and doubled up one octave C4 as well.
What I want to do is write some code that takes in any series of midi message numbers, like the example above, evaluates them, then tells the user what musical entity they have played, including inversions, doublings, other possible interpretations, etc...
There would be a database/dictionary/object/array/data-thing of some type that contains many different patterns, then the code would compare the incoming numbers to this set of patterns to find the correct one(s)...
Not looking for code answers as much as an idea as to how to go about even getting started with such a thing in javascript, as this would be for the web...
I just don't really have any idea how to start going about this, but any thoughts or examples or resources that could point me in the right direction would be most appreciated.
Thanks! XD
I've been stuck in my head for a long time, but I'm looking for an idea that will be more acceptable than the solution I found myself, I'm curious about your thoughts.
You know the wheel of luck, every object has an equal probability of coming out. If there are 20 objects, there is a 5% chance that one of these objects will come off the wheel.
The rationale for this is simple and easy to design.
However, if the probability of some objects appearing on this wheel is 1%, the probability of others is 5% and the probability of others is 60%, how do we design this.
My solution that I found but consumes a lot of power is as follows.
dividing the wheel into 100 parts and separating 60 divisions into 1 product, 1 division into 1 product and 5 divisions into 1 products.
But this is a very simple and problematic solution.
I would be grateful if you tell me your ideas, what is the logic under how the people who make the systems I mentioned design it.
You can do this in Python:
import random
letters = ['a', 'b', 'c']
weights = [10, 1, 5]
result = random.choices(letters, weights, k=50)
print(''.join(sorted(result)))
The 50 is the amount of random choices to generate.
An example output would be aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbccccccccccccccc
Documentation for the random module is at https://docs.python.org/3/library/random.html
I am entirely new to both Qualtrics and Javascript (as such, apologies for how elementary this question may be). I have a survey on the former that will require using Javascript in a couple of the different Blocks in the survey to count the number of answers provided by a user in a number of different text entry boxes (all of which are in just one Block).
We want to pay respondents by the number of suggestions they make, so I really just want to count how many of the different text entry boxes in that one question Block have something written in them, to then use as a variable in another Block at the end of the survey to pay respondents based on how many questions they answered.
Conceptually, I assume it'll just mean initializing a counter, looping over the N text entry boxes we have, adding +1 to the counter for every one of those N boxes in which anything has been entered (I'm not worrying about whether what is entered is actually meaningful to us, assuming people don't just enter spaces), and keeping that variable to use in the very last block of the survey (where we tell them what they have earned, which is a fixed amount per suggestion). I just can't seem to find even the building blocks/ elementary syntax to implement that very simple counter through Googling and searching around here (I tried to get a bit of inspiration from these questions but no success so far: (1) Qualtrics Word Counter Javascript; (2) Qualtrics: javascript - text entry).
Any help would be appreciated!
You can do this in your survey flow after the text entry questions block:
Embedded Data: count = 0
Branch: If Text Question 1 Not Empty
Embedded Data: count = $e{ e://Field/count + 1 }
Branch: If Text Question 2 Not Empty
Embedded Data: count = $e{ e://Field/count + 1 }
etc...
At the end count will equal the number of text entry questions answered.
I'm setting up a simple Qualtrics survey with one question with a Loop & Merge function (in this one block); in Loop & Merge field 1, I've provided the URLs to my media files. The respondents have to select the right answer from two answer options (let's say Yes/No). All all my files are set up as a Loop & Merge within one question so that I won't have to create 100 separate questions for each individual media file.
This works great, however, I would also like to score my respondents' answers. The regular "scoring" feature in Qualtrics doesn't seem to work for me, since I can only provide one scoring option per question (i.e. I could only say that the first answer is always 1 point, and the second answer is always 0 points). However, the correct answer varies between my files (sometimes it's Yes/the first option; sometimes it's No/the second option).
I'm thinking there might be a way to list the correct answer (=i.e. the answer that should receive 1 point) in Field 2 in the Loop & Merge function; and then include some (javascript?) code in the question which would check the survey taker's answer choice against the "correct answer" in Field 2 of the Loop & Merge function for each media file. The code would assign "1" point if the participant's selected answer corresponds to Field 2 for each media file.
How would I write the (javascript) code to calculate a score for each question and an overall score at the end? (I don't need survey takers to see their score, but once a person is done, I would like to quickly see what their final overall score is, say 72 out of 100 possible points.)
Update: In the loop/merge function, I've added the right answer (for each file) in Field2, the incorrect answer in Field3. As suggested below, I've piped loop fields (2 and 3) into my question choices. I've added code in Field4 about whether or not the order of the answer options should be changed (0,1; 0= don't change order, 1= change order) so that the options always occur in the same order (for example, always Choice 1 = "Yes", Choice 2 = "No".) I've (unsuccessfully) tried to use the following JS code to refer to Field 4:
if (${lm://Field/4}==1) {
(choiceNum = ${lm://Field/3}, ${lm://Field/2})
}
If there is a way to work without JavaScript, I'd be glad to hear about that option as well.
Thank you so much!
How about this without JavaScript:
Include your two choices as loop fields: Field 2 is correct answer, Field 3 is incorrect answer
Pipe your loop fields (2 and 3) into your question choices
Randomize the choices
Score the question: Choice 1/Field 2 = 1 point, Choice 2/Field 3 = 0 points.
I have an array full of quotes, and on load a random quote is displayed. The problem I'm having is everything works fine when I only have 2 quotes loaded, but when I added the entire list, it no longer runs.
Here is the code that works-
<div id="quotes">Quotes</div>
<script type="text/javascript">
var quotes = [
"<i>Some people feel the rain. Others just get wet.</i><br><b>Bob Marley</b>",
"<i>Do not pray for an easy life, pray for the strength to endure a difficult one. </i><br><b>Bruce Lee</b>"
];
document.getElementById('quotes').innerHTML = quotes[Math.floor(Math.random() * quotes.length)];
</script>
The above works as expected, however when I add the rest of the quotes (as seen below) The script no longers works.
<div id="quotes"></div>
<script type="text/javascript">
var quotes = [
"<i>Some people feel the rain. Others just get wet.</i><br><b>Bob Marley/b>",
"<i>Do not pray for an easy life, pray for the strength to endure a difficult one. </i><br><b>Bruce Lee</b>",
"<i>Success is not final, failure is not fatal: it is the courage to continue that counts.</i><br><b>Winston
Churchill</b>",
"<i>If your dreams don’t scare you they’re not big enough.</i><br><b></b>",
"<i>It takes courage to grow up and become who you really are.</i><br><b>E.E. Cummings</b>",
"<i>All endings are also beginnings, we just don’t know it yet.</i><br><b></b>",
"<i>There are three kinds of people: Those who make it happen, those who watch it happen, and
those who wonder what the heck happened.</i><br><b></b>",
"<i>There are people so poor, that the only thing they have is money.</i><br><b> </b>",
"<i>Things do not happen. Things are made to happen.</i><br><b>John F. Kennedy</b>",
"<i>Destiny is a name often given in retrospect to choices that had dramatic consequences.</i><br><b>J.K. Rowling</b>",
"<i>When I was 5 years old, my mother always told me that happiness was the key to life.
When I went to school, they asked me what I wanted to be when I grew up. I wrote
down ‘happy’. They told me I didn’t understand the assignment, and I told them they didn’t
understand life.</i><br><b>John Lennon</b>",
"<i>Not all those who wander are lost</i><br><b>JRR Tolkien</b>",
"<i>We all die. The goal isn’t to live forever, the goal is to create something that will.</i><br><b></b>",
"<i>Strive for progress, not perfection.</i><br><b></b>",
"<i>What defines us is how well we rise after falling.</i><br><b></b>",
"<i>It’s not hard to make decisions once you know what your values are.</i><br><b>Roy E. Disney</b>",
"<i>Sorry’s not good enough.</i><br><b></b>",
"<i>I may not be there yet, but I’m closer than I was yesterday.
Every day is a new beginning. Stay away from what might have been and look at what can
be.</i><br><b></b>",
"<i>Who inspires you?</i><br><b></b>",
"<i>If you play by the rules long enough, then you can change the game.</i><br> <b>Enders Game</b>"
];
document.getElementById('quotes').innerHTML = quotes[Math.floor(Math.random() * quotes.length)];
</script>
You can't have newlines in JavaScript strings. You need to change this:
"str part
the rest"
to this:
"str part\nthe rest"
or
"str part\n"
+ "the rest"
You should check the JavaScript console for errors; this can help you debug
Also, you can write multiple-lined strings like this:
var str = "beginning \
continue \
end.";
The backslash before the line break is another solution.
The line breaks inside strings caused the issue. Here is fully working code:http://jsfiddle.net/whizkid747/5tyrY/
<div id="quotes">Quotes</div>
<script type="text/javascript">
var quotes = [
"<i>Some people feel the rain. Others just get wet.</i><br><b>Bob Marley</b>",
"<i>Do not pray for an easy life, pray for the strength to endure a difficult one.</i><br><b>Bruce Lee</b>",
"<i>Success is not final, failure is not fatal: it is the courage to continue that counts.</i><br><b>WinstonChurchill</b>",
"<i>If your dreams don’t scare you they’re not big enough.</i><br><b></b>",
"<i>It takes courage to grow up and become who you really are.</i><br><b>E.E. Cummings</b>",
"<i>All endings are also beginnings, we just don’t know it yet.</i><br><b></b>",
"<i>There are three kinds of people: Those who make it happen, those who watch it happen, and those who wonder what the heck happened.</i><br><b></b>",
"<i>There are people so poor, that the only thing they have is money.</i><br><b> </b>",
"<i>Things do not happen. Things are made to happen.</i><br><b>John F. Kennedy</b>",
"<i>Destiny is a name often given in retrospect to choices that had dramatic consequences.</i><br><b>J.K. Rowling</b>",
"<i>When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down ‘happy’. They told me I didn’t understand the assignment, and I told them they didn’t understand life.</i><br><b>John Lennon</b>",
"<i>Not all those who wander are lost</i><br><b>JRR Tolkien</b>",
"<i>We all die. The goal isn’t to live forever, the goal is to create something that will.</i><br><b></b>",
"<i>Strive for progress, not perfection.</i><br><b></b>",
"<i>What defines us is how well we rise after falling.</i><br><b></b>",
"<i>It’s not hard to make decisions once you know what your values are.</i><br><b>Roy E. Disney</b>",
"<i>Sorry’s not good enough.</i><br><b></b>",
"<i>I may not be there yet, but I’m closer than I was yesterday. Every day is a new beginning. Stay away from what might have been and look at what can be.</i><br><b></b>",
"<i>Who inspires you?</i><br><b></b>",
"<i>If you play by the rules long enough, then you can change the game.</i><br> <b>Enders Game</b>"
];
document.getElementById('quotes').innerHTML = quotes[Math.floor(Math.random() * quotes.length)];
</script>