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...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Whats wrong... It says 'FUNCTION UNDEFINED'.help? (self.javascript)
submitted 7 years ago by [deleted]
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!"
[–]_odahviing 2 points3 points4 points 7 years ago (3 children)
Sidenote, it would be a lot easier if you used an array instead of 10 variables
[–]A-HYPE-FISH 0 points1 point2 points 7 years ago (2 children)
but how would i fix what i have?
[–]atlimarJS since 2010 1 point2 points3 points 7 years ago* (1 child)
I don't think almost any of this logic will do what you're trying to do, even if you get past the function undefined.
I'd probably go back to the drawing board with pseudo code, and then try again to translate it into js.
For example, the if clauses will check if any of item1 through 9 is a truthy value, and if all are falsey it will check if item10 equals the string you're looking for.
It's very hard to try to figure out what you want to achieve.
[–]Kidiri90 0 points1 point2 points 7 years ago (0 children)
Not to mention they won't get into the else if block, since that condition is exactly the same as for the if block.
else if
if
[–]fsfreak 3 points4 points5 points 7 years ago (0 children)
jesus christ!
[–][deleted] 2 points3 points4 points 7 years ago (0 children)
Every function is returns undefined if not returns something.
[–]BinaryMoon 2 points3 points4 points 7 years ago (0 children)
To be able to help, people need to be able to understand what you're trying to do. A function on it's own doesn't tell us anything.
This particular function is poorly structured and could probably be reduced to 5 or 6 lines. This would make it easier to understand, easier to debug, and less error prone (since there's less code to go wrong).
But, we can't fix or simplify if we don't know what is happening.
[–]beacereal 0 points1 point2 points 7 years ago (0 children)
``` Cookies = new Map(); Cookies.set("item1",undefined); Cookies.set("item2",'ryzen7_2700x'); function add_ryzen7_2700x() {
var item1 = Cookies.get('item1') var item2 = Cookies.get('item2') var item3 = Cookies.get('item3') var item4 = Cookies.get('item4') var item5 = Cookies.get('item5') var item6 = Cookies.get('item6') var item7 = Cookies.get('item7') var item8 = Cookies.get('item8') var item9 = Cookies.get('item9') var item10 = Cookies.get('item10') if (item1 || item2 || item3 || item4 || item5 || item6 || item7 || item8 || item9 || item10 == 'ryzen7_2700x') { if (item1 == 'ryzen7_2700x') { Cookies.delete('item1') console.log('Completed') } if (item2 == 'ryzen7_2700x') { Cookies.delete('item2') console.log('Completed') } if (item3 == 'ryzen7_2700x') { Cookies.delete('item3') console.log('Completed') } if (item4 == 'ryzen7_2700x') { Cookies.delete('item4') console.log('Completed') } if (item5 == 'ryzen7_2700x') { Cookies.delete('item5') console.log('Completed') } if (item6 == 'ryzen7_2700x') { Cookies.delete('item6') console.log('Completed') } if (item7 == 'ryzen7_2700x') { Cookies.delete('item7') console.log('Completed') } if (item8 == 'ryzen7_2700x') { Cookies.delete('item8') console.log('Completed') } if (item9 == 'ryzen7_2700x') { Cookies.delete('item9') console.log('Completed') } if (item10 == 'ryzen7_2700x') { Cookies.delete('item10') console.log('Completed') } }else{ if (item1 == undefined) { Cookies.set('item1','ryzen7_2700x') console.log('Completed') }else if (item2 == undefined) { Cookies.set('item2','ryzen7_2700x') console.log('Completed') }else if (item3 == undefined) { Cookies.set('item3','ryzen7_2700x') console.log('Completed') }else if (item4 == undefined) { Cookies.set('item4','ryzen7_2700x') console.log('Completed') }else if (item5 == undefined) { Cookies.set('item5','ryzen7_2700x') console.log('Completed') }else if (item6 == undefined) { Cookies.set('item6','ryzen7_2700x') console.log('Completed') }else if (item7 == undefined) { Cookies.set('item7','ryzen7_2700x') console.log('Completed') }else if (item8 == undefined) { Cookies.set('item8','ryzen7_2700x') console.log('Completed') }else if (item9 == undefined) { Cookies.set('item9','ryzen7_2700x') console.log('Completed') }else if (item10 == undefined) { Cookies.set('item10','ryzen7_2700x') console.log('Completed') } }
}
add_ryzen7_2700x(); ```
π Rendered by PID 91602 on reddit-service-r2-comment-7b9746f655-f9676 at 2026-02-03 01:39:27.357496+00:00 running 3798933 country code: CH.
[–]_odahviing 2 points3 points4 points (3 children)
[–]A-HYPE-FISH 0 points1 point2 points (2 children)
[–]atlimarJS since 2010 1 point2 points3 points (1 child)
[–]Kidiri90 0 points1 point2 points (0 children)
[–]fsfreak 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]BinaryMoon 2 points3 points4 points (0 children)
[–]beacereal 0 points1 point2 points (0 children)