wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
local bar = 73
local bar = 73
Correct.
Lua
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if item = 4 then print('hello') end
if item == 4 then print('hello') end
Use ==.
Lua
function foo(): void {{ return 7; }}
function foo(): number {{ return 7; }}
Return type mismatch.
TypeScript
println('info')
println("info")
Double quotes.
Scala
[13, 85, 60
[13, 85, 60]
Close bracket.
Python
if index = 21:
if index == 21:
Use == for comparison.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<input type='text' value='world'>
<input type='text' value='world' name='title'>
Add name attribute.
HTML
println('hello')
println("hello")
Double quotes.
Scala
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
yield index
yield index
Correct yield.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
if (data = 24) {{}}
if (data == 24) {{}}
Use ==.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if foo = 61 then print('world') end
if foo == 61 then print('world') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
index == '77'
index === 77
Use strict equality.
JavaScript
'info' + 43
'info' + str(43)
Can't add int to string.
Python
echo output test
echo 'output test'
Quote to prevent splitting.
Shell
if x > 32 print('hello')
if x > 32: print('hello')
Colon missing after if.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if (num = 95) {}
if (num == 95) {}
Use ==.
Dart
def compute(): print('world')
def compute(): print('world')
Indent function body.
Python
4count = 10
count4 = 10
Variable cannot start with digit.
Python
[39, 39, 74
[39, 39, 74]
Close bracket.
Python
age: data id: hello,
age: data id: hello
Remove comma.
YAML
$data[64]
if ($data.Count -gt 64) {{ $data[64] }}
Check bounds.
PowerShell
var x int
var x int
Correct.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print('data')
print('data')
Correct.
R
String data = 'message';
String data = "message";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
echo 'value'
echo 'value';
Add semicolon.
PHP
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
const data = 79; data = 42;
let data = 79; data = 42;
Cannot reassign const.
JavaScript
if index = 27
if index == 27
Use ==.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for (int i=0; i<70; i++) {{}}
for (int i=0; i<70; i++) {{}}
Correct.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for num in range(32) print(num)
for num in range(32): print(num)
Colon after for.
Python
list.forEach(function(count) {{ console.log(count); }})
list.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
print 'message'
print 'message';
Add semicolon.
Perl
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
arr[49]
if (length(arr) >= 49) arr[49]
Check length.
R
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
function baz(a:string){{return a;}} baz(3);
function baz(a:string){{return a;}} baz('value');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
switch(c){{ case 68: break; }}
switch(c){{ case 68: break; default: break; }}
Add default case.
Java
let v=vec![4,90,21]; let head=&v[0]; v.push(21);
let mut v=vec![4,90,21]; let head=v[0]; v.push(21);
Copy instead of reference.
Rust
fn process() -> i32 {{ 31 }}
fn process() -> i32 {{ 31 }}
Correct.
Rust
SELECT * FROM orders WHRE name=77;
SELECT * FROM orders WHERE name=77;
Fix WHERE.
SQL
for i=1,36 do print(i) end
for i=1,36 do print(i) end
Correct.
Lua
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
if ($a = 97) {{}}
if ($a -eq 97) {{}}
Use -eq.
PowerShell
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:71}};
Add missing property.
TypeScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
print 'result'
print('result')
print needs parentheses.
Python
if (x = 75)
if (x == 75)
Use ==.
R
$data[22] = 5;
if (isset($data[22])) $data[22] = 5;
Check existence.
PHP
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
List(39,33,25)
List(39,33,25)
Correct.
Scala
let x = 'data'
let x = "data"
Double quotes.
Swift
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
DELETE FROM items WHERE status=97
DELETE FROM items WHERE status=97;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
const a;
const a = 48;
Initialize const.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
["test", 54]
["test", 54]
Correct.
JSON
let mut item=36; let r1=&mut item; let r2=&mut item;
let mut item=36; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
'info' + 19
'info' + 19.to_s
Convert int.
Ruby
while a > 66 a -= 1
while a > 66: a -= 1
Colon missing after while.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
bar
bar()
Add parentheses.
Kotlin
if [ $val = 53 ]; then
if [ "$val" = 53 ]; then
Quote variable.
Shell
let val = 54;
let val = 54;
Correct.
JavaScript
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO items VALUES ('result',7)
INSERT INTO items (id, email) VALUES ('result',7);
Specify columns.
SQL
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala