0 votes

I want the user to first list what activities they do in a day and then specify how many hours per day they spend on each activity. In the end, I want to end up with a variable that looks something like this:

>>activities = {"Exercise" -> 4, "Watching TV" -> 9, "Travel" -> 15}

But, of course, both the key and the relation are defined by the user.


The way I've gone about it now is this:

*question: Write any regular activities here
	*type: text
	*multiple
	*placeholder: Travel, exercise, watching TV...
	*save: activities

*for: activity in activities
	*question: How many hours you spend *per week* on {activity} on average?
		*type: number

I don't know how to save their answer to that last question as a relation to the first, and I can't find anything about it in the manual. Any help would be much appreciated!

by (240 points)

1 Answer

0 votes
Best answer

Richard Möhn kindly answered this in the Slack. I'll write the answer here:

"I think this would get you all the way to what you want:"

>> hours_for_activities = {}
*for: activity in activities
	*question: How many hours you spend *per week* on {activity} on average?
		*type: number
		*save: hours_for_activity
		
	>> hours_for_activities[activity] = hours_for_activity

And he followed up with an explanation on how to list the items or sum them:

*for: activity, hours in hours_for_activities
	You spent {hours} h on {activity}.

>> total_hours = 0
*for: activity, hours in hours_for_activities
	>> total_hours = total_hours + hours

Thanks, Richard!

by (240 points)
Welcome to Guidedtrack Q&A, where you can ask questions and receive answers from other members of the community.
134 questions
144 answers
55 comments
40 users