I have done the following:
function longestWord (sentenceAnalyze1R) {
console.log(sentenceAnalyze1R);
var eachword = 0;
var WordList = sentenceAnalyze1R.split(’ ');
for(var i=WordList - 1; i<0; i--)
I am so close but I need the extra help.
The link that is very similar to this is here:
There is one difference, it is the initial variable:
var words: ‘The cargo went to the hound’
I’m trying to find the longest word that is also the last word. I think it is the exact same process. I just don’t know how to count in reverse.
var = 'hectameters, mm, dm, meter, centimeter'
/// assume that this file is running in the background and if you get the longest word
that is also the last word, you should be able to display it and then you will pass the challenge
but you have to run a for loop as part of the instructions
function longestcount (measureAnalyze1R) {
console.log(sentenceAnalyze1R);
var counter = 0;
var LastWord = [];
var WordList = measureanalyze1R.split(' ');
console.log(WordList);
for(var i=WordList.length-1; i<0; i--); {
if (WordList[i].length>counter){counter=WordList[i].length;
};
console.log(WordList[i]);
return counter
I am trying to find the last and the longes word. I have learned the format to find the last word. Can I use -= to find the longest word?
The question is that I want to find the longest word but that the array has to count backwards and it has to be the last word. notice that centimeter and hectameter have the same length? Hold on, I’m rearranging it
var multiplesOfThreeSums = 0;
var numberCounter = 0;
for (var i=1;i<=300;i++){
if (i % 3 === 0){
numberCounter++;
multiplesOfThreeSums += i;
}
}
This goes three hundred cycles by multiples of three
For example:
first iteration: 3
secont iteration: 9 (3+6) — 6 plus the previous term
third iteration: 18 (9+9) ----9 plus the previous term
could I not count backwards using - = in the condition part?
- = is bolded and spaced for arguments sake for right now, wont be like that in the code. Im trying to see if I can count down from a “ceiling” instead of up to it
var = 'hectameters, mm, dm, meter, centimeter'
/// assume that this file is running in the background and if you get the longest word
that is also the last word, you should be able to display it and then you will pass the challenge
but you have to run a for loop as part of the instructions
function longestcount (measureAnalyze1R) {
console.log(sentenceAnalyze1R);
var counter = 0;
var LastWord = [];
var WordList = measureanalyze1R.split(' ');
console.log(WordList);
for(var i=WordList.length-1; i<0; i--); {
if (WordList[i].length-1;counter){counter=WordList[i].length; counter--
};
console.log(WordList[i]);
return counter
I’m trying to use counter at the end but the -1 is overriding it. but if I remove the -1 it counts it (the loop) forward. I would like to use a similar approach as the link I posted, How do I go about converting an array (in this case a string) with multiple strings to a single string?
That admin person uses ++; im 100% sure you can use – at the end
You have a number of syntax and logical errors in your code.
The syntax errors that I mentioned before are still there. Also you are doing for(var i=WordList.length-1; i<0; i--). Look very closely at that. Your for loop will never run unless WordList is empty, in which case it will run infinitely.
Im just confused with that statement because the for loop actually runs and it runs backwards, but it doesnt count consecutively (from the last index to the first index) but i’m checking the other parts.
What is the psuedocode associated with what is happening there? So that I can have some direction. Not the answer neccesarily, but what is currently happening. I’m stepping out for a second but I am definitely interested in continuing to pursue this topic so I will be back.
var snacks = 'cookies pecans ants fudge bee';
var arraynow = snacks.split
output: ['cookies'] ['pecans'] ['ants'] ['fudge'] ['bee']
///now I assume I can do the following:
for(var i=arraynow.length]; i<0; i--); {
if (WordList[i].length>counter){counter=WordList[i].length;
///or I could do this; this only counts the first item though; based on the console this prints out the last item of the list; this is part of a function alread
for(var i=arraynow-1; i<0; i--); {
if (WordList[i].length>counter){counter=WordList[i].length;
//////or I could do this; the for loop will still look like above ///this one is formatted and the counter is used and I believe I can use this counter in my example above but this is a seperate example
var Manyant = ‘ant 123, ant 234, ant 345, ant 456’;
function countAllFromAnt(antX) {
var counter=0;
var filteredArr = [];
var arrwords = antX.split(‘,_‘)
for (var i= 0; i<arrWords.length; i++){
if (arrwords[i].startswith(‘ant’)){filteredArr.push(arrWords[i]);
counter++;
}
}
Return counter;
}
countAllfromant
I was trying to solve it on my own but I need to know if one of these options will work.