Action
Choose a Student
I’m a teacher and I want to call on different students each time. I also sometimes give quizzes by asking direct questions to keep them engaged and score the quality of their answers.
This action randomly chooses a student name from a list in Drafts, tallies the number of times they have been called on, and adds to their score [2] according to your choice in a prompt. The more times someone has been called on [1] the less likely they will be called on again. The format for your draft should be:
Class Name
John Johnson, 19, 5
Fred Coleman, 5, 14
Bob Bobson, 6, 9
In this scheme:
John Johnson has been called on 19x and accumulated a total of 5 points.
You can also use iOS shortcuts to choose the correct class list (Draft) by time of day using this Shortcut:
https://www.icloud.com/shortcuts/4c95b2aad19c42d8b9487bfb0fab566d
Action Link at https://actions.getdrafts.com/a/19M
Steps
-
script
// ** Pulls in the draft let originalText = draft.content; // **Separates the title and the list of names var splitLines = originalText.split("\n"); var title = splitLines.slice(0, 1); var namesSplit = splitLines.slice(2); let fullArray = [] // Function to put these lines into an object function createPersonRecord(fullLine) { var scoreArray = fullLine.split(", "); let personObject = {"name": scoreArray[0], "timesCalled": parseInt(scoreArray[1]), "score": parseInt(scoreArray[2])}; return personObject; } // ** Turns all of the listed names into objects nested in an array. It iterates through and puts each one into this format as an object, then pushes it to the array. for (var i = 0; i < namesSplit.length; i++) { fullArray.push(createPersonRecord(namesSplit[i])); } // ** Adds up the total scores of all students so far as an inverse of their times called number let sumOfTimesCalled = 0 for (var i = 0; i < namesSplit.length; i++) { sumOfTimesCalled += 1 / fullArray[i].timesCalled; } // Takes the random number generated and multiplies it by the total scores let test = Math.random() let luckyStudent = Math.random() * sumOfTimesCalled; // Picks out the correct student from the array let testSum = 0 for (var i = 0; luckyStudent > testSum; i++) { testSum += 1 / fullArray[i].timesCalled; luckyStudentName = fullArray[i].name; luckyStudentIndex = i } // Alerts the student name and prompts for a score var mods = [ "1", "2", "3", "4", "5", ]; /* ------ Prompt ------ */ var p = Prompt.create(); p.title = "🥳 " + luckyStudentName + " 🥳"; for (var mod of mods) { p.addButton(mod); } var con = p.show(); // Actions if not cancelled if (con) { if (p.buttonPressed == "1") { var score = "1"; } if (p.buttonPressed == "2") { var score = "2"; } if (p.buttonPressed == "3") { var score = "3"; } if (p.buttonPressed == "4") { var score = "4"; } if (p.buttonPressed == "5") { var score = "5"; } } else { context.fail(); } // Adds one to their score and alerts their name fullArray[luckyStudentIndex].timesCalled = fullArray[luckyStudentIndex].timesCalled + 1; fullArray[luckyStudentIndex].score = fullArray[luckyStudentIndex].score + parseInt(score); // Recreates the Draft from the adjusted array and replaces it let updatedText = title + "\n"; for (var i = 0; i < fullArray.length; i++) { updatedText += "\n" + fullArray[i].name + ", " + fullArray[i].timesCalled + ", " + fullArray[i].score; } draft.content = updatedText; draft.update();
Options
-
After Success Default Notification Info Log Level Info