Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scriptq question type #48

Closed
wants to merge 3 commits into from
Closed

Add scriptq question type #48

wants to merge 3 commits into from

Conversation

seragunn
Copy link
Contributor

The goal here is to add questions requiring some computation to verify.

Example of new scriptq question type for checking permutations

@jverzani
Copy link
Owner

Cool. So you pass in an expression and not a function? Is there some reason that is preferable? I would have guessed the function might have f(this.val, ...) signature so that things are run in a different scope. (But I haven't really thought any of this through.)

Also, is it possible to use external javascript libraries in the evaluation of correct or not? I don't have any in mind, but I could see that being of interest.

@seragunn
Copy link
Contributor Author

Also, is it possible to use external javascript libraries in the evaluation of correct or not? I don't have any in mind, but I could see that being of interest.

Yes! In the screenshot, the Permutation class is defined in a separate file.

So you pass in an expression and not a function? Is there some reason that is preferable?

The question is: how much of the JavaScript code should be written in your markdown/Julia versus in an external JavaScript file. If we're writing the question in Julia then you'd have to wrap the expressions in (str) => { ... } and that function would only be used for the contents. But if you write a closure in a separate JavaScript file then you could pass in closure(...). So it kind of forces you to keep the JavaScript in a separate file...maybe that's preferable.

@seragunn
Copy link
Contributor Author

...Going to make a new branch doing it via functions for comparison

@seragunn seragunn marked this pull request as draft April 21, 2024 00:15
@jverzani
Copy link
Owner

Let me know what works out best from your point of view.

@seragunn
Copy link
Contributor Author

I like the implementation in #49 better:

  • it encourages you to keep most of your JavaScript code in JavaScript rather than within a Julia string.
  • you don't need to have a specifically named correct: boolean variable at the end, just any function which returns a boolean. So a cleaner interface.
  • for some short functions it can even be less verbose doing (i) => 43 <= i && i <= 48 rather than var correct = 43 <= this.value && this.value <= 48;.

I suggest reviewing #49 and closing this PR.

@seragunn seragunn closed this Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants