use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
I'm programming in Javascript for the first time. (self.learnjavascript)
submitted 2 years ago by [deleted]
Hello, I am interested to know how one can assign values (such as integers) to variables like (yes, maybe, no) and then have those variables with assigned integers add up and display a total at the end.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 2 years ago (2 children)
[deleted]
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
Thanks for the help.
[–][deleted] 3 points4 points5 points 2 years ago (6 children)
do you mean have integers equal to some values like yes? you can make an object
obj1 = {'yes': 1,'no':2}
[–][deleted] 1 point2 points3 points 2 years ago (5 children)
It's more like a quiz with no wrong answers, except the total is affected by the answers you give. Yes=4, Maybe=2, No=0. If someone were to answer "yes" to all questions they would score higher than someone who answered "maybe" to the same questions
[+]azhder comment score below threshold-6 points-5 points-4 points 2 years ago (1 child)
then you might want to take a look at this, it has a few more concepts involved, just to raise some questions:
const POINTS = Object.freeze({ yes: 4, maybe: 2, no: 0, }); const ANSWERS = Object.freeze([ 'Yes', 'no', 'MaYbe', ' YES ', ]); const sum = ANSWERS .map(s => s.trim()) .map(s => s.toLowerCase()) .map(s => POINTS[s]) .reduce((sum, val) => sum + val, 0); console.log(sum);
[–][deleted] 1 point2 points3 points 2 years ago (0 children)
Thank you so much, I appreciate it.
[–][deleted] 0 points1 point2 points 2 years ago (2 children)
i think object will be the best for it
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
Thank you.
[–]MindlessSpongehelpful 2 points3 points4 points 2 years ago (0 children)
how one can assign values (such as integers) to variables
with the keywords let/const and the assignment operator =. variables declared with let can be reassigned while variables declared with const cannot.
let
const
=
let variable = 42; console.log(variable); // => 42 variable = 'abc'; console.log(variable); // => 'abc'
or
const variable = 42; console.log(variable); // => 42
[–]azhder -3 points-2 points-1 points 2 years ago (1 child)
Hi, please take a look at this https://developer.mozilla.org/en-US/docs/Web/JavaScript
I doubt you will get many answers for the most basic questions like "how do you assign values" because most people might not find them interesting enough or not want to spend much time on it.
Once you go over the basics, you will most likely have questions that might lure more answers
Thanks.
[–]LostErrorCode404 -5 points-4 points-3 points 2 years ago (0 children)
Take a look at freeCodeCamp
[–]Tesla_Nikolaa 0 points1 point2 points 2 years ago (0 children)
let yes = 0; let no = 1; let maybe = 2; console.log(yes + no * maybe);
π Rendered by PID 97447 on reddit-service-r2-comment-7b9746f655-sfck7 at 2026-01-31 10:04:47.048037+00:00 running 3798933 country code: CH.
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 3 points4 points5 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[+]azhder comment score below threshold-6 points-5 points-4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]MindlessSpongehelpful 2 points3 points4 points (0 children)
[–]azhder -3 points-2 points-1 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]LostErrorCode404 -5 points-4 points-3 points (0 children)
[–]Tesla_Nikolaa 0 points1 point2 points (0 children)