Guest User

Untitled

a guest
Oct 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. 'use-strict'
  2.  
  3. var dictionary = {};
  4.  
  5. function addValues(){
  6. var llave = document.getElementById("llave").value;
  7. var valor = document.getElementById("valor").value;
  8. dictionary[llave] = valor;
  9. }
  10.  
  11. function printJSON(){
  12. var string = '{<br>"diccionario":[<br>'
  13. for(var llave in dictionary){
  14. var valor = dictionary[llave];
  15. var tipo = "String";
  16. if(!isNaN(valor)){
  17. tipo = "Number";
  18. }else if(valor=="true"||valor=="false"){
  19. tipo = "Bool";
  20. }
  21. string += '{"llave":"'+llave+'",<br>"valor":"'+valor+'",<br>"tipo":"'+tipo+'"},<br>';
  22. }
  23. string = string.slice(0,string.length-5);
  24. string += "<br>";
  25. string += ' ]<br>}'
  26. document.getElementById("format").innerHTML=string;
  27. }
  28.  
  29. function printXML(){
  30. var string = '<dictionary><br>'
  31. for(var llave in dictionary){
  32. var valor = dictionary[llave];
  33. var tipo = "String";
  34. if(!isNaN(valor)){
  35. tipo = "Number";
  36. }else if(valor=="true"||valor=="false"){
  37. tipo = "Bool";
  38. }
  39. string += '<element><br>';
  40. string += '<llave>'+llave+'</llave><br>';
  41. string += '<tipo>'+tipo+'</tipo><br>';
  42. string += '<valor>'+valor+'</valor><br>';
  43. string += '</element><br>';
  44. }
  45. string += '</dictionary>'
  46. document.getElementById("format").innerHTML=string;
  47. }
  48.  
  49. window.onload = function(){
  50. var button = document.getElementById("Add");
  51. button.addEventListener("click",addValues);
  52. };
Add Comment
Please, Sign In to add comment