Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So I am creating a "Silly Story Generator" in Javascript and after fixing a few errors that popped up I encountered "SyntaxError: missing ) after argument list"
After reading more about it I learned that it occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.
I checked my code and I cannot seem to find the mistake, string on line 38 looks okay.
Thank you.
randomize.addEventListener('click', result);
function result() {
if (customName.value !== '') {
let name = customName.value;
}
if (document.getElementById("uk").checked) {
let weight = Math.round(300);
let temperature = Math.round(94);
}
story.text = ""
story.style.visbility = 'visible';
var newStory = storyText;
let xItem = randomValueFromArray;
let yItem = randomValueFromArray;
let zItem = randomValueFromArray;
function newStory(buttonPress) {
newStory.contentString.replace("insertX", "insertY", "insertZ")
content.contentString.replace("xItem ", "yItem", "zItem");
}
}
Your Code is Badly formatted.
At newStory.contentString.replace("insertX", "insertY", "insertZ";)
You had a semi-colon inside the the parenthesis.
You are also missing two curly braces near the end.
I suggest getting a good IDE or using the formatting features that come with the one you use.
randomize.addEventListener('click', result);
function result() {
if (customName.value !== '') {
let name = customName.value;
}
if (document.getElementById("uk").checked) {
let weight = Math.round(300);
let temperature = Math.round(94);
}
story.text = ""
story.style.visbility = 'visible';
var newStory = storyText;
let xItem = randomValueFromArray;
let yItem = randomValueFromArray;
let zItem = randomValueFromArray;
function newStory(buttonPress) {
newStory.contentString.replace("insertX", "insertY", "insertZ")
content.contentString.replace("xItem ", "yItem", "zItem");
}
}
you have written a semicolon before the closing parentheses
newStory.contentString.replace("insertX", "insertY", "insertZ");
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to get the value from the input in the html code and edit it, then put it in the div, but I get undefined.
HTML
<input type="text" id='doller'>
<button onclick="convertUsdToRiyal()">convert usd to Riyal</button>
<div id="result"></div>
<script src="js1.js"></script>
JS
function convertUsdToRiyal() {
'use strict';
var amount = document.getElementById('doller').Value,
result = 3.75 * amount,
massage = document.getElementById('result');
massage.innerHTML = amount;**//here i get undefined**
}
The "value" attribute should be in lower case, because javascript is a case sensitive language. So the instruction will be :
var amount = document.getElementById("doller").value.
Here is the code in es6 (ECMAscript 2015) for the convertUsdToRiyal() function:
convertUsdToRiyal = () => {
let amount = document.getElementById("doller").value;
result = 3.75 * amount;
massage = document.getElementById("result");
massage.innerHTML = result;
};
or just simply:
convertUsdToRiyal = () => {
document.getElementById("result").innerHTML = 3.75*document.getElementById("doller").value;
};
document.getElementById('doller').Value should be changed to document.getElementById('doller').value.
Value should be lowercase.
/*global console*/
function convertUsdToRiyal() {
var amount = document.getElementById('doller').value,
result = 3.75 * amount,
massage = document.getElementById('result');
console.log(amount);
massage.innerHTML = result;
}
<input type="text" id='doller'>
<button onclick="convertUsdToRiyal()">convert usd to Riyal</button>
<div id ="result"></div>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am doing an excercise that challenges me a bit, and I just thought that might be a good idea to ask for some help here. I know it might be very easy question for the majority of you, but as I am new to coding hope this won't botter you too much.
Below is my code associated with the excercise. The code shouldn't run in my opinion as the var weapon is not specified. The problem is that the code runs and the console visualises some outcome.
I would assume there is something wrong with my conditional statements, but might be wrong..
var room = 'gallery';
var suspect = 'Ms. Van Cleve';
var weapon = '';
var solved = false;
if (room === 'billiards room') {
weapon = 'pool stick';
if (suspect === 'Mr. Parkes')
solved = true;
} else if (room === 'gallery') {
weapon = 'trophy';
if (suspect === 'Ms. Van Cleve')
solved = true;
}
if (solved) {
console.log(suspect + ' did it in the ' + room + ' with the ' + weapon + '!');
}
//Outcome is "Ms. Van Cleve did it in the gallery with the trophy!"
Your code result does not depend on weapon. Have a look at what you have defined
var room = 'gallery';
var suspect = 'Ms. Van Cleve';
var weapon = '';
var solved = false;
and the else if part of your code
} else if (room === 'gallery') { // TRUE
weapon = 'trophy';
if (suspect === 'Ms. Van Cleve') // TRUE
solved = true; // so now solved is true
}
As solved is true you get console output because
if (solved) {
console.log(suspect + ' did it in the ' + room + ' with the ' + weapon + '!');
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to modify an element in jQuery programmatically, i.e. a number in docID increments up to a maximum number. I'm replacing text on a series of images on a page from Download to View. If I use #ctl00_cphMainContent_dlProductList_ct100_ctl00_lnkProofDownload instead of docID in the $(docID).text(...) part of the code, the text gets replaced correctly. When I use the docID variable in its place, it doesn't work.
What am I doing wrong here?
Thanks.
var max = 10;
var count = 100;
var s1 = "#ctl00_cphMainContent_dlProductList_ct";
var s2 = "_ctl00_lnkProofDownload";
var docID = "";
for (i = 1; i <= max; i++)
{
docID = s1.concat (count++, s2);
$(document).ready(function() {
$(docID).text(function(i, oldText) {
return oldText === 'Download' ? 'View' : oldText;
});
});
}
This is the HTML code that is being modified. The word Download is replaced by View.
<a id="ctl00_cphMainContent_dlProductList_ctl00_ctl00_lnkProofDownload"
href="../../../Controls/StaticDocProof.ashx?qs=op/5WlcUxeg849UT973Mwf0ZnNcMLfe3JYAe7EnJORsdyETYV1vcKaj0ROc2VrN5fXfYjO2MM6BUYXzX2UKmog=="
>Download</a>
It looks like you have done a couple things incorrectly in your code, including using a 1 instead of an l. If it was supposed to be a 100 instead of a l00, something more like this would work:
jQuery(function () {
var max = 10,
count = 100,
s1 = 'ctl00_cphMainContent_dlProductList_ct',
s2 = '_ctl00_lnkProofDownload',
docID;
for (var i = count; i <= count + max; i++) {
docID = s1 + i + s2;
jQuery('#' + docID).text(function (idx, oldText) {
return oldText === 'Download' ? 'View' : oldText;
});
}
});
Fiddle here: http://jsfiddle.net/ochguL2d/
Otherwise, let us know if it is supposed to be l00 for a different answer.
Your a element has this in the middle (note two "els"):
ctl00_ctl00
… but your docID has this in the middle (note a "one and an el"):
ct100_ctl00
Fix your HTML, and your code works as-is: http://jsfiddle.net/5c7hwyts/
However, that's an odd way to write jQuery.
Here's a different approach:
$('a').text(function(i, oldText) {
var num= parseInt(this.id.split('ctl00_cphMainContent_dlProductList_ct')[1]);
if(num>=100 && num<110) {
return oldText === 'Download' ? 'View' : oldText;
}
});
Fiddle
The element IDs your are trying to match in your code are not the ones in the DOM.
// This is what you want to match
var domID = "#ctl00_cphMainContent_dlProductList_ct100_ctl00_lnkProofDownload"
^ that is an L
// this what your code is trying to match in its first iteration
var docID = "#ctl00_cphMainContent_dlProductList_ct10_ctl00_lnkProofDownload";"
^ that is a 1 (one)
Also, your code's max variable needs to be a two char numeric string with leading zeros starting at zero, not an integer starting at 10.
Personally, I would just:
// On DomReady...
$(document).ready(function() {
// loop through all anchors that have "lnkProofDownload" in their ID attribute
$('a[id*="lnkProofDownload"]').each(function() {
// and if the text is set to "Download", change it to "View"
if ($(this).text() == "Download") {
$(this).text("View");
}
});
});
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am learning nodeJS and I have this syntax error which I don't understand.
Can someone point out what is the syntax error, why I am getting it, and how do I bypass it?
var http = require('http');
var url = require('url');
var server = http.createServer(function(req,res) {
if (req.method == 'POST') {
return res.end("Only get requests");
}
var st = url.parse(req.url,true);
if (st.indexOf("parsetime") > -1) {
var time = st.substring(st.indexOf("iso"));
var date = new Date(time);
var out = '{
"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
}';
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(out);
} else if (st.indexOf("unixtime") > -1) {
var time = st.substring(st.indexOf("iso"));
var date = new Date(time);
var out = "{
'unixtime':"+date.getTime()+"
}";
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(out);
} else {
return res.end("404");
}
});
server.listen(process.argv[2]);
The syntax error is on line 11 : " var out = '{ "
Remove the single quotes from here:
var out = '{
"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
}';
Change the above to:
var out = {
"hour": date.getHours(),
"minute": date.getMinutes(),
"second": date.getSeconds(),
};
Or if I may be mistaken for the string to contain a JSON object, you need to do declare the out that way and stringify using:
out = JSON.stringify(out);
The problem is that you tried to have a multi-line string, which you can't do like that in JavaScript. It is probably easier to do it like this:
var out = '{';
out+='"hour":'+date.getHours(),
out+='"minute":'+date.getMinutes(),
out+='"second":'+date.getSeconds()
out+='}';
Or, even easier, just define the object, then use JSON.stringify() to turn it into a string:
var outObj = {
hour:date.getHours(),
minute:date.getMinutes(),
second:date.getSeconds()
};
var obj=JSON.stringify(outObj);
This just defines a normal object, then turns it into JSON
Remove quotes
var out = {"hour":'+date.getHours()+',
"minute":'+date.getMinutes()+',
"second":'+date.getSeconds()+',
};
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a collection (of about 61000) strings that look like
"(((((((((.(((((.&.)))))))))))))) 11,26 : 6,20 (-9.37 = -16.05 + 6.56 + 0.13) GCCAACUGACGUUGUU&AAUAAUUCAGUUGGU"
There are a variable number of spaces (1-3) between each part of the string.
Ultimately what I want is to convert this string to a javascript object:
{
parens: "(((((((((.(((((.&.))))))))))))))",
sRNAstart: 11,
sRNAend: 26,
mRNAstart: 6,
mRNAend: 20,
netEnergy: -9.37,
bindingEnergy: -16.05,
sRNAOpenEnergy: 6.56,
mRNAOpenEnergy: 0.13,
sequences: "GCCAACUGACGUUGUU&AAUAAUUCAGUUGGU"
}
This sounds like a job for RegEx man, bust sadly I am not him. Can anyone help me figure out a way to accomplish this?
here is a way to use regexp to parse the string, with one internal work-around for those pesky parens:
var s="(((((((((.(((((.&.)))))))))))))) 11,26 : 6,20 (-9.37 = -16.05 + 6.56 + 0.13) GCCAACUGACGUUGUU&AAUAAUUCAGUUGGU";
var ob=s.split( /([\s]{1,4}|[,=+:()])/ )
.filter( /./.test, /\w/ )
.map(function(chunk, i){
if(i===0) this.parens= s.split(" ")[0];
this[[ "sRNAstart","sRNAend","mRNAstart","mRNAend","netEnergy",
"bindingEnergy","sRNAOpenEnergy","mRNAOpenEnergy","sequences"
][i]]= +chunk || (chunk==="0"? 0 : chunk);
return this;
},{})[0] ; //end ob
alert(
JSON.stringify(
ob,
null,
"\t"
)
);
result:
{
"parens": "(((((((((.(((((.&.))))))))))))))",
"sRNAstart": 11,
"sRNAend": 26,
"mRNAstart": 6,
"mRNAend": 20,
"netEnergy": -9.37,
"bindingEnergy": -16.05,
"sRNAOpenEnergy": 6.56,
"mRNAOpenEnergy": 0.13,
"sequences": "GCCAACUGACGUUGUU&AAUAAUUCAGUUGGU"
}
EDIT: removed use of non-capturing parens for more x-browser compat with OLD browsers.
EDIT: adjustments: make "0" into 0, avoid setting this.parens each time, formatting, and argument cleanup.
A Javascript split() with multiple delimiters should yield an array of all of the values you need.
From there, it's simple string concatenation.
This expression will not ensure that the parentheses are matched, but it should break out everything in your pattern.
([(.&)]+)\s*(\d+),(\d+)\s*:\s*(\d+),(\d+)\s*\(([-.\d]+)\s*=\s*([-.\d]+)\s*\+\s*([-.\d]+)\s*\+\s*([-.\d]+)\)\s*([GCAU&]+)
Here is an alternative that should also work for you and is cross-browser.
Javascript
function parse(string) {
if (typeof string !== "string") {
throw new TypeError("Attribute must be a string.");
}
var props = ["parens", "sRNAstart", "sRNAend", "mRNAstart", "mRNAend", "netEnergy", "bindingEnergy", "sRNAOpenEnergy", "mRNAOpenEnergy", "sequences"],
array = string.split(/[)]?\s+[(:=+]?\s*|,/),
object = {},
value;
if (array.length !== props.length) {
throw new Error("String could not be converted.");
}
do {
value = array.shift();
object[props.shift()] = +value || value;
} while (props.length);
return object;
}
var ref = "(((((((((.(((((.&.)))))))))))))) 11,26 : 6,20 (-9.37 = -16.05 + 6.56 + 0.13) vGCCAACUGACGUUGUU&AAUAAUUCAGUUGGU";
for(var i = 0; i < 3; i += 1) {
console.log(ref, parse(ref));
ref = ref.replace(/(\s+)/g, function (all, whitespace) {
return whitespace + " ";
});
}
On jsfiddle