I have my background change color when value is entered, but how do I add numerous value

Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

For example v==3 turns red.  I would like to turn red if 9, 15, 21, 25, 27, 29 is entered.   How do I go about doing this?  Do I have to do invidual lines or do I put && between values?

My code knowledge is about .01.. I just find what I'm looking for online and tweak it.

 

var v = Number(event.value);
if (v==1) {event.target.fillColor = color.green;}
else if (v==2) {event.target.fillColor = color.yellow;}
else if (v==3) {event.target.fillColor = color.red;}
else event.target.fillColor = color.white;

 

 

TOPICS
JavaScript

Views

47

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 05, 2022 May 05, 2022

You can't use && that would mean that multiple values exist at the same time, instead use || (or)

(v==1 || v==9 || v==15...etc)

Likes

Translate

Translate
Community Expert ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

You can't use && that would mean that multiple values exist at the same time, instead use || (or)

(v==1 || v==9 || v==15...etc)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

LATEST

Thank you, much appreciated!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines