2017-03-29 79 views
0

我不想在Javascript中運行Python代碼,我想將其完全轉換爲JS代碼。我不知道python,Can body可以幫我解決這個問題。謝謝。如何將此python代碼轉換爲Javascript

print ("Please input the # of books you've read this year") 
BooksAlready=int(input()) 
print ("Please input the # of weeks that have already passed this year") 
WeeksAlready=int(input()) 
x=(78/52) 
c=x*WeeksAlready-BooksAlready 
if (BooksAlready/WeeksAlready)>x: 
    print ("You're on point, go have some fun!") 
else: 
    print ("Go read, you piece of uneducated crap") 
    print ("You have") 
    print (c) 
    print ("books left to read this week to get on point") 
+0

假設你想讓它在像NodeJS這樣的終端上運行? –

+1

[Python to Javascript轉換器]的可能重複(http://stackoverflow.com/questions/22595989/python-to-javascript-converter) –

+1

這可能會幫助你 - http://stackoverflow.com/questions/22595989/python -to-javascript-converter – Mamun

回答

0

這將在瀏覽器的js控制檯中運行。 prompt將無法​​在node.js中工作,您可以通過process.argv訪問命令行參數。

console.log("Please input the # of books you've read this year"); 
console.log("Please input the # of weeks that have already passed this year"); 

var WeeksAlready=parseInt(prompt()), 
BooksAlready=parseInt(prompt()), 
x=(78/52), 
c=x*WeeksAlready-BooksAlready; 

if (BooksAlready/WeeksAlready>x){ 
    console.log("You're on point, go have some fun!"); 
} 
else{ 
    console.log ("Go read, you piece of uneducated crap"); 
    console.log ("You have"); 
    console.log (c); 
    console.log ("books left to read this week to get on point"); 
} 
+0

非常感謝 –

相關問題