Jump to content

hisoka

Members
  • Content count

    568
  • Joined

  • Last visited

Everything posted by hisoka

  1. thanks , I have another question concerning the web console output : As you can see , when I run the above code , the output is many numbers each in a line . Is it possible to get , in the web console , all numbers in the same line ? if yes , could you please tell me how ?
  2. thank you . Could you please suggest me a Mozilla Firefox program that runs JavaScript code , that is easy to use and far more flexible and comfortable than the web console , where I can copy paste the content i need without any problem . May be an ad don that I do not know that is compatible with Firefox 58 . I have Mozilla Firefox 58 and , unfortunately , an add on like , for example , Execute JS is not compatible with my version but with the old versions of Firefox best regards
  3. Thank you for your reply . But , unfortunately , your answer does not meet my question I asked if there is a way or a method to copy only the numbers from the web console without the Scratchpad/4:6:4 and debugger eval code:6:4 . So If there is a way or a method , what is it ? best regards
  4. hisoka

    understanding javascript code

    I have trouble understanding this long javascript code : var p = 0; var r = ''; var b = new Array(); for(var i=0; i<32768; i++) b[i] = 0; function main() { incPtr(1); incVal(10); while(b[p]>0) { decPtr(1); incVal(8); incPtr(1); decVal(1); } decPtr(1); incVal(5); echo(String.fromCharCode(b[p])); incPtr(1); incVal(6); while(b[p]>0) { decPtr(1); incVal(5); incPtr(1); decVal(1); } decPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); incVal(2); while(b[p]>0) { decPtr(1); decVal(7); incPtr(1); decVal(1); } decPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); incVal(3); while(b[p]>0) { decPtr(1); incVal(4); incPtr(1); decVal(1); } decPtr(1); incVal(1); echo(String.fromCharCode(b[p])); decVal(4); echo(String.fromCharCode(b[p])); incPtr(1); incVal(3); while(b[p]>0) { decPtr(1); decVal(4); incPtr(1); decVal(1); } decPtr(1); decVal(1); echo(String.fromCharCode(b[p])); incPtr(1); incVal(3); while(b[p]>0) { decPtr(1); incVal(4); incPtr(1); decVal(1); } decPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); incVal(2); while(b[p]>0) { decPtr(1); decVal(4); incPtr(1); decVal(1); } decPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); incVal(4); while(b[p]>0) { decPtr(1); decVal(10); incPtr(1); decVal(1); } decPtr(1); decVal(3); echo(String.fromCharCode(b[p])); incPtr(1); incVal(4); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(2); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(8); incPtr(1); decVal(1); } decPtr(1); incVal(1); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(5); incPtr(1); decVal(1); } decPtr(1); incVal(3); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); decVal(7); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(3); incPtr(1); b[p] = prompt('', '').charCodeAt(0); echo(String.fromCharCode(b[p])); incVal(2); incPtr(1); b[p] = prompt('', '').charCodeAt(0); echo(String.fromCharCode(b[p])); incPtr(1); b[p] = prompt('', '').charCodeAt(0); echo(String.fromCharCode(b[p])); incPtr(1); b[p] = prompt('', '').charCodeAt(0); echo(String.fromCharCode(b[p])); decVal(4); incPtr(1); b[p] = prompt('', '').charCodeAt(0); echo(String.fromCharCode(b[p])); incPtr(3); incVal(8); while(b[p]>0) { decPtr(1); incVal(4); incPtr(1); decVal(1); } decPtr(1); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(9); incPtr(1); decVal(1); } decPtr(1); decVal(3); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(4); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(1); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(3); incPtr(2); incVal(6); while(b[p]>0) { decPtr(1); incVal(5); incPtr(1); decVal(1); } decPtr(1); incVal(3); incPtr(1); incVal(1); incPtr(2); incVal(8); while(b[p]>0) { decPtr(1); incVal(4); incPtr(1); decVal(1); } decPtr(1); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(7); incPtr(1); decVal(1); } decPtr(1); decVal(3); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(1); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(4); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(4); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(1); incPtr(2); incVal(10); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); decVal(1); incPtr(2); incVal(11); while(b[p]>0) { decPtr(1); incVal(10); incPtr(1); decVal(1); } decPtr(1); incVal(6); incPtr(2); incVal(6); while(b[p]>0) { decPtr(1); incVal(5); incPtr(1); decVal(1); } decPtr(1); incVal(3); decPtr(22); while(b[p]>0) { decPtr(5); decVal(1); incPtr(5); decVal(1); } decPtr(5); while(b[p]>0) { incPtr(10); incVal(1); decPtr(10); while(b[p]>0) { decVal(1); } } incPtr(6); decVal(1); while(b[p]>0) { decPtr(5); decVal(1); incPtr(5); decVal(1); } decPtr(5); while(b[p]>0) { incPtr(9); incVal(1); decPtr(9); while(b[p]>0) { decVal(1); } } incPtr(6); incVal(2); while(b[p]>0) { decPtr(5); decVal(1); incPtr(5); decVal(1); } decPtr(5); while(b[p]>0) { incPtr(8); incVal(1); decPtr(8); while(b[p]>0) { decVal(1); } } incPtr(6); while(b[p]>0) { decPtr(5); decVal(1); incPtr(5); decVal(1); } decPtr(5); while(b[p]>0) { incPtr(7); incVal(1); decPtr(7); while(b[p]>0) { decVal(1); } } incPtr(6); incVal(5); while(b[p]>0) { decPtr(5); decVal(1); incPtr(5); decVal(1); } decPtr(5); while(b[p]>0) { incPtr(6); incVal(1); decPtr(6); while(b[p]>0) { decVal(1); } } incPtr(6); while(b[p]>0) { incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); decVal(1); decPtr(8); while(b[p]>0) { decVal(1); } } incPtr(8); while(b[p]>0) { incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); incPtr(1); echo(String.fromCharCode(b[p])); decPtr(9); while(b[p]>0) { decVal(1); } } } function incPtr(n) { if(p < 32676 - n) p += n; else p = 0; } function decPtr(n) { if(p > n - 1) p -= n; else p = 255; } function incVal(n) { if(b[p] < 255 - n) b[p] += n; else b[p] = 0; } function decVal(n) { if(b[p] > n - 1) b[p] -= n; else b[p] = 255; } function echo(c) { r += c; } var isWS = (typeof(alert)=='undefined'); if(isWS) prompt = function() {WScript.Echo("Unable to run this program.\n'prompt' is not supported under Windows Script Host!");return "";}; main(); if(r!='') if(isWS) WScript.Echo(r); else alert(r); is it obfuscated ? if yes how to get the original code ? so that i could understand what it does any idea?
  5. hisoka

    understanding javascript code

    what do you mean by that . Could you please make it more simple to understand ?
  6. I have this javascript code and when I run it it does not print the result : function isprime(n) { if (n<2) { return false; } var q = Math.floor(Math.sqrt( n)); for( i = 2 ; i<= q ; i++) { var result = n%i; if(result==0) { return false; } else { document.write(result); } } } var prime = isprime(100); I do not know why ? any help on what is the problem is and how to solve it
  7. hisoka

    javascript code does not show result

    Now I am trying to take a number as input in box and once I press ok all the primes that are less than it are generated I did like this : function calculate(x) { var x = prompt("enter a number"); var results = "" ; var y=parseInt(x); for(i=0 ; i<n ; i++) { var isprime = false; for(j=2 ; j<n ; j++) { if(i%j===0 && i!==j) { isprime = true; } } if(isprime===false) { results += i + "\n"; } } return results; } console.log(calculate(x)); but it gives no result . I know that something I added in the code is wrong but I do not know how to correct it .
  8. hisoka

    javascript code does not show result

    I changed that code with another code : function calculate(n) { for(i=0 ; i<=n ; i++) { var isprime = false; for(j=2 ; j<=n ; j++) { if(i%j===0 && i!==j) { isprime = true; } } if(isprime===false) { console.log(i+"\n"); } } } console.log(calculate(17)); then it gives me : 1 2 3 5 7 11 13 17 undefined I do not know why get undefined and how to correct the code so that I do not get undefined
  9. hisoka

    javascript code does not show result

    That is why I put the code here and asked for help because I do not know how that function will return a value , how it will print it in the computer screen so that I can see it . What to do so that the function is well written and how to do it !! Generally I know that an integer is a prime if it is not divisible by any prime less or equal to its square root hence we have in that code the var q = Math.floor(Math.sqrt( n)); it gives the square root of a number combined with math.floor and the for loop it takes n % i which is n % all numbers that are less or equal to the square root of n and dismisses or ignore all the numbers that are divisible by n as they are not prime . Moreover the role of the function is not to look if n is a prime or not otherwise to give all the primes between 2 and n My problem is I cannot make it print the values . You wrote that is it not well written , it does not return a value ....... I know all that . So what do you suggest to make it well writeen , return a value and print it in the screen . What is the substitution ? any suggest from you on what to do ?
  10. function sum(input){ if (toString.call(input) !== "[object Array]") return false; var total = 0; for(var i=0;i<input.length;i++) { if(isNaN(input[i])){ continue; } total += Number(input[i]); } return total; } console.log(sum([1,2,3])); console.log(sum([100,-200,3])); console.log(sum([1,2,'a',3])); In this code I do not understand what is total += Number(input[i]); Number ????
  11. That is it thank you . Sorry , I did not read the comments . Next time I will read the comments too and look al all possible corners of the page Yes I realise . However if the computer begins to calculate from 0 not from 1 like humans so why the output here : var array = [1, 2, 3] ; var x = array.length ; console.log(x) ; is 3 and not 2 ?
  12. Normally , the second parameter passed to the function is 3 not 2 because the size of [1,2,3] is 3 not 2 . I know it is 3 through this : var array = [1, 2, 3] ; var x = array.length ; console.log(x) ; the output is 3 not 2 and 2 exponent 3 is 8 not 4
  13. now the things become more clear : the shift operator is used to change the position of the numbers in the set and the and operator is used to concatenate them together so that they form all possible subset . What I understood , too , is that the number of subsets in a set of x elements is 2 exponent x . The code above is taken from this page : http://www.w3resource.com/javascript-exercises/javascript-function-exercise-21.php In the end of the code , there is this instruction : console.log(subset([1, 2, 3], 2)); and the expected output from it is , as mentioned , Expected output : [[2, 1], [3, 1], [3, 2], [3, 2, 1]] which are 4 subsets however if we take a look at the array in the instruction above , we will see that it contains 3 elements . So 2 exponent 3 is 8 . So normally we need to have 8 subsets and not 4 subsets . So why we got 4 subsets ?
  14. that what I , unfortunately , did . However , I run it again with all the console.log statements inside it and , now the logic of the code becomes far more clear to me than before . Moreover , now I understand very well the logic beyond using the Math.pow function . However even with this : I still cannot grasp very well the use of bitwise operators in the code and this : (1 << i) is 1 x & (1 << i) is 0 result: Array [ 2 ] x is 3 i is 2 (1 << i) is 4 x & (1 << i) is 0 (1 << i) is 2 x & (1 << i) is 2 (1 << i) is 1 x & (1 << i) is 1 result: Array [ 2, 1 ] x is 4 i is 2 (1 << i) is 4 x & (1 << i) is 4 (1 << i) is 2 x & (1 << i) is 0 (1 << i) is 1 x & (1 << i) is 0 result: Array [ 3 ] x is 5 i is 2 (1 << i) is 4 x & (1 << i) is 4 (1 << i) is 2 x & (1 << i) is 0 (1 << i) is 1 x & (1 << i) is 1 result: Array [ 3, 1 ] x is 6 i is 2 (1 << i) is 4 x & (1 << i) is 4 (1 << i) is 2 x & (1 << i) is 2 (1 << i) is 1 x & (1 << i) is 0 result: Array [ 3, 2 ] x is 7 i is 2 (1 << i) is 4 x & (1 << i) is 4 (1 << i) is 2 x & (1 << i) is 2 (1 << i) is 1 x & (1 << i) is 1 result: Array [ 3, 2, 1 ] I am still unable to understand how and why the bitwise operators are used to determine which element is pulled from the set and pushed in the subset ?? Could you please make it more clear to me
  15. with all due respect , after running the version you posted to me , things become more obscure : Here is the whole code : function subset(arra, arra_size) { var result_set = [], result; for (var x = 0; x < Math.pow(2, arra.length); x++) { console.log('x is ' + x); result = []; i = arra.length - 1; console.log('i is ' + i); do { console.log('(1 << i) is ' + (1 << i)); console.log('x & (1 << i) is ' + (x & (1 << i))); if ((x & (1 << i)) !== 0) { result.push(arra[i]); } } while (i--); console.log('result:'); console.log(result); if (result.length >= arra_size) { result_set.push(result); } } return result_set; } var matrix = subset([2, 5, 6], 2); I run it line by line : console.log('x is ' + x); gives x is 0x is 1x is 2x is 3x is 4x is 5x is 6x is 7 console.log('i is ' + i); gives i is 2i is 2i is 2i is 2i is 2i is 2i is 2i is 2 console.log('(1 << i) is ' + (1 << i)); console.log('x & (1 << i) is ' + (x & (1 << i))); give (1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1(1 << i) is 4(1 << i) is 2(1 << i) is 1 x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 1x & (1 << i) is 0x & (1 << i) is 2x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 2x & (1 << i) is 1x & (1 << i) is 4x & (1 << i) is 0x & (1 << i) is 0x & (1 << i) is 4x & (1 << i) is 0x & (1 << i) is 1x & (1 << i) is 4x & (1 << i) is 2x & (1 << i) is 0x & (1 << i) is 4x & (1 << i) is 2x & (1 << i) is 1 console.log('result:'); console.log(result); give result:result:result:result:result:result:result:result: 255,266,26,56,5,2 except the last result all the results of console log the version you gave me are obscure and made me more confused Moreover I still do not understand how math.pow gives the number of all possible subset ?!!! I read the tutorials about javascript in w3school site which were very useful and helped me a lot but even so I could not get a clear understanding about the code above . Justsomeguy could you please tell me what should I do in order to be able to understand very well the code above ?
  16. yes i know what is a subset but i do not know the answer for my 4 questions . That is why I asked them
  17. Syntactic , this what I could understand so far f unction subset(arra, arra_size) { var result_set = [], result; for (var x = 0; x < Math.pow(2, arra.length); x++) { result = []; i = arra.length - 1; do { if ((x & (1 << i)) !== 0) { result.push(arra[i]); } } while (i--); if (result.length >= arra_size) { result_set.push(result); } } return result_set; } console.log(subset([1, 2, 3], 2)); the for loop , loops Math.pow(2, arra.length) time . For example here it loops 2 exponent 3 time that is 8 times i = arra.length - 1; is , of course , array length -1 if( (x & (1 << i)) !== 0) each time it loops it looks if x & (1 << i)) !== 0 put the result in the empty array result [] result.push(arra[i]) while(i--); is a reverse loop . It reverse the numbers . if( result.length >= arra_size) put a condition so that while does not loop infinitely result_set.push(result); push the sub arrays in the array result_set I cannot understand the code semantically : 1) math.pow is an exponent mathematical function . What has it to do with array length and for loop in the code above . What is the logical beyond using it ? 2) what is the logic beyond using bitwise operators in the if condition ? if( (x & (1 << i)) !== 0) 3) i = arra.length - 1; what is the logic beyond substracting the array length from 1 ? 4) in the function parameters I understand why the arra is used but why arra-size is used ? here is the purpose of it : http://www.w3resource.com/javascript-exercises/javascript-function-exercise-21.php no I do not understand why it returns what it does for the input because i as I mentioned above i do not get what the code line by line , semantically , does ?
  18. There are things I cannot understand in this code : function subset(arra, arra_size) { var result_set = [], result; for(var x = 0; x < Math.pow(2, arra.length); x++) { result = []; i = arra.length - 1; do { if( (x & (1 << i)) !== 0) { result.push(arra[i]); } } while(i--); if( result.length >= arra_size) { result_set.push(result); } } return result_set; } console.log(subset([1, 2, 3], 2)); The Math.pow() function returns the base to the exponent power, that is, baseexponent. But I do not understand why it is used in the code above ? what is the purpose of it ? and why it is used in combination with arr.length what does this mean : i = arra.length - 1; why bitwise and shift operators are used here in this code ? for what purpose ? (x & (1 << i)) !== 0) what is the purpose of making an empty array ? result = [];
  19. ok I understand the items inside the array are numbers so why we need to convert them into numbers ??? and therefore why do not we simply write : total += input[i]; ?
  20. hisoka

    mozilla web console for html + javascipt both

    it is a good idea but in a text editor , I do not see my errors when I run the code in the browser because they are not shown like in scratchpad or web console . if there is an error I got only a blank page . that , of course , makes it very hard - at least for a beginner like me- to notice my errors and therefore correct them . Moreover I need , every time , to save my code as HTML and then launch it in the browser . No good thing
  21. I looked for a tool inside mozilla - by clicking Menu then developer - in which I can write a code composed of both javascript and html . Unfortunately , I could not find in the developer any tool that accepts both html and javascript together . web console and scratchpad do not accept html . Is there - may be - a tool inside Mozilla firefox or an extension that I overlooked and that could help me write a code of both html and javascript because I do not want to download a javascript developer tool from google
  22. you said Number convert the string into numbers so why here in this code I got NAN function sum() { var total = 0; var letters = ["A" , "B"]; for(x = 0 ; x < letters.length ; x++) { total += Number(letters[x]); } document.write(total); } var x = sum(); if you run it in the browser you will get NOT A NUMBER OR NAN
  23. Hello glad to be again in w3schools forum when I opened a zip file in hex editor , I noticed that after the end of the file , there are additional hex values . For example in a zip file I opened in a hex editor there was like this : 50 4B 05 06 00 00 00 00 02 00 02 00 6F 00 00 00 84 09 00 00 00 00 50 4B 05 06 hex values represent the end of the zip file . However , I do not understand what represent these additional hex values after the end 00 00 00 00 02 00 02 00 6F 00 00 00 84 09 00 00 00 00 ??
  24. Thank you , I will try to put more efforts before asking the question
  25. could you please tell me what do some of these above mean ? what does Number of this disk mean ? what does Disk where central directory starts mean ? what are central directory records ?
×